Bangla font number in PHP

  • Author: Sajjad Hossain
  • |
  • Added: Feb 13, 2016
  • |
  • In: PHP Scripts

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 much 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 the worldwide open source programming language and it always helps us to do something new, create new feature as we like and makes our projects easy. We can solve many big problems and create new programs in shortcut way using php. Ok, let's go into the main point. For converting English numbers into Bangla font we have to create a php function. This function helps 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 function 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 change file encoding into UTF-8 to show Bangla font output. click to encoding into notepad++ and select UTF-8 from the list. 

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 us. If you like this article then share it with others and contribute to broad PHP community.

Search
I am...

Sajjad Hossain

I have five years of experience in web development sector. I love to do amazing projects and share my knowledge with all.

NEED HOSTING?
Are you searching for Good Quality hosting?
You can Try It!
Connect Social With PHPAns
Top