0

No matter what Bengali number I provide in $ben_num variable, it always outputs 1, like with 1111111111. Whatever the length of the $ben_num the output is the same length of ones (1s).

I tried to run the code in

  1. WriteCodeOnline
  2. PHPTester

It works perfectly fine in these sites. Output is whatever bengali number of strings I give (eg 1234567890).

Might PHP version be the problem?

$ben_num = "১২৩৪৫৬৭৮৯০";
bn2enNumber($ben_num);

function bn2enNumber ($number){
   $search_array= array("১", "২", "৩", "৪", "৫", "৬", "৭", "৮", "৯", "০");
   $replace_array= array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
   $en_number = str_replace($search_array, $replace_array, $number);

   echo $en_number;
}
10
  • The encoding of the PHP file is probably wrong. Try to use your code editor to change the file's encoding to UTF-8 Commented Jul 21, 2017 at 18:16
  • 1
    Most likely your setup does not support multi byte strings. You want to read about that extension: php.net/manual/en/book.mbstring.php Commented Jul 21, 2017 at 18:16
  • coderodour - Yes working fine Commented Jul 21, 2017 at 18:23
  • Nick J - Yes my code editor is in UTF-8 Commented Jul 21, 2017 at 18:24
  • what is your local PHP version? Commented Jul 21, 2017 at 18:24

1 Answer 1

1

Make sure your source code file (.php file) is saved in UTF-8

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.