如何将unicode字符串转换为int?

My code is :

<?php

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

?>

but, output is 0 instead of 19.

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

PHP casting rely on strtod and will only manage ascii and not ARABIC-INDIC UTF-8 characters althought they mean digits; as there is no conversion from those characters casting them will return zero.

You should test against to something like \x{0660}-\x{0669} (the digits codes) convert them to ascii equivalents and then cast to proper type.

@javadaskari, for now fix it as @Frayne Konok 's function convert_number, you can apply it even if the input number is ascii (it will remain valid).

Then I see reasonable you to open a bug in https://bugs.php.net saying that since (int)"string" started to accept utf-8 string, it should have accepted those characters meaning number. Php is likely to handle generic user input and the case you identified might encounter other use of that function that behave in a manner unexpected by the user.

But I don't grant that the bug you seem to have discovered will be "fixed" in php as me and you see reasonable, also I let you check there if is duplicate.