32,000+ SUBSCRIBERS CAN'T GO WRONG !!!

phpans
GET TOP ARTICLES, SNIPPETS, SCRIPTS IN YOUR INBOX FOR FREE!

Delivered by GET EMAIL UPDATES FeedBurner
We always respect your privacy and take protecting it seriously.
We won't Spam You

Bangla font number in PHP

, 0,
Bangla font number in PHP
Bangla font number is a method to convert english number 0,1,2,3,4,5,6,7,8,9 to bangla font ০,১,২,৩,৪,৫,৬,৭,৮,৯ . This is very important for a bangla website to show all content in bangla like number time & date and many more. Today I am going to discuss with you how we can do that. How we convert english font into bangla easily. Yes can do that easily , PHP functions help us to do that. PHP is worldwide opensouce programming language and it's alwasy helps us to do somthing new, create new feature as we like and makes our projects easy. We can solve many big problems and create new programms in shortcut way using php. Ok let's go into main point. For convert english numbers into bangla font we have to create a php function. This function help us to convert numbers. Create a function name as bfn($str) and we are going a to pass a variable into bfn() function. We pass out text by $str and when a number will pass by this $str variable then bfn() function convert numbers into bangla font. Create function and write down this code into this function.
function bfn($str) { 
$search=array("0","1","2","3","4","5",'6',"7","8","9");
$replace=array("০","১","২","৩","৪","৫",'৬',"৭","৮","৯");
return str_replace($search,$replace,$str);
}

We created our function. Look how this fucntion works. This function is very easy. We just used str_replace function into our function. We replaced every number into bangla font. Now we are going to see how this function works. for that create a file name as index.php open this into notepad++ . We should chnage file encoding into UTF-8 to show bangla font output. click to encoding into notepad++ and select UTF-8 from list.
/attachment/qpnvjyl.png
then write down this code
<?php
function bfn($str) {
$search=array("0","1","2","3","4","5",'6',"7","8","9");
$replace=array("০","১","২","৩","৪","৫",'৬',"৭","৮","৯");
return str_replace($search,$replace,$str);
}


$myText = "The time is 2:47 am";
echo bfn($myText);
?>

This program will execute and show result like
The time is ২ঃ৪৭ am

That means our function works fine and we can convert numbers into Bangla font easily. I hope this function helps you to complete your program and project. If you face any problem or If you have any question about this article you can comment here or contact with us. If you like this article then share it with others and contribute to broad PHP community.

Download PDF
Is this article helpful for you?





captcha

  • Connect
  •       
Top
Create an free account and start learning & sharing! Sign Up