javadaskari javadaskari - 5 months ago 22
PHP Question

PHP : How can I cast unicode string to int?

My code is:

<?php

echo((int)("١٩")); //Number is 19

?>


but, output is 0 instead of 19.

Answer

Make two array of two types number, the use the str_replace function. I use the Bangla character for this example, you must change it to your language.

function convert_number($your_num){
    $find = array("০", "১", "২", "৩", "৪", "৫", "৬", "৭", "৮", "৯");
    $replace = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
    return str_replace($find, $replace, $your_num);
}

Just call the function where you need to convert your number.

echo convert_number("১৯");

Outoput: 19