Last active
July 20, 2019 10:53
-
-
Save RyadPasha/f3c21af8f3402769225cb807c54e64a6 to your computer and use it in GitHub Desktop.
Convert Arabic/Persian numbers to English numbers in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function conv2EnNum($str) { | |
$str = str_replace(['٠','١','٢','٣','٤','٥','٦','٧','٨','٩'], range(0, 9), $str); // Convert Arabic numbers | |
$str = str_replace(['۰','۱','۲','۳','۴','۵','۶','۷','۸','۹'], range(0, 9), $str); // Convert Persian numbers | |
return preg_replace('/[^0-9\.,]/', '', $str); | |
} | |
echo conv2EnNum('٠١٢٣٤٥٦٧٨٩'); // -> 01213456789 | |
echo conv2EnNum('١٣.٥'); // -> 13.5 | |
echo conv2EnNum('۴۷۶'); // -> 476 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment