Last active
March 6, 2023 15:13
-
-
Save Habetdin/b79cd2bf374bf9248cb1eac064203b2d to your computer and use it in GitHub Desktop.
Convert Eastern-Arabic, Bengali, Devanagari, Myanmar, Persian numerals to Western-Arabic (ASCII)
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 normalizeNumerals($string) { | |
$numerals_ascii = range(0, 9); // Western Arabic | |
$numerals_arabic = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩']; // Eastern Arabic | |
$numerals_bengali = ['০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯']; // Bengali | |
$numerals_devanagari = ['०', '१', '२', '३', '४', '५', '६', '७', '८', '९']; // Devanagari (Nagari) | |
$numerals_myanmar = ['၀', '၁', '၂', '၃', '၄', '၅', '၆', '၇', '၈', '၉']; // Myanmar (Burmese) | |
$numerals_persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; // Persian | |
$string = str_replace($numerals_arabic, $numerals_ascii, $string); | |
$string = str_replace($numerals_bengali, $numerals_ascii, $string); | |
$string = str_replace($numerals_devanagari, $numerals_ascii, $string); | |
$string = str_replace($numerals_myanmar, $numerals_ascii, $string); | |
$string = str_replace($numerals_persian, $numerals_ascii, $string); | |
return $string; | |
} |
Nginx version:
location ~ '(?:\xD9[\xA0-\xA9]|\xDB[\xB0-\xB9]|\xE0\xA5[\xA6-\xAF]|\xE0\xA7[\xA6-\xAF]|\xE1\x81[\x80-\x89])' {
rewrite '^(.*)(?:\xD9\xA0|\xDB\xB0|\xE0\xA5\xA6|\xE0\xA7\xA6|\xE1\x81\x80)(.*)$' $10$2;
rewrite '^(.*)(?:\xD9\xA1|\xDB\xB1|\xE0\xA5\xA7|\xE0\xA7\xA7|\xE1\x81\x81)(.*)$' $11$2;
rewrite '^(.*)(?:\xD9\xA2|\xDB\xB2|\xE0\xA5\xA8|\xE0\xA7\xA8|\xE1\x81\x82)(.*)$' $12$2;
rewrite '^(.*)(?:\xD9\xA3|\xDB\xB3|\xE0\xA5\xA9|\xE0\xA7\xA9|\xE1\x81\x83)(.*)$' $13$2;
rewrite '^(.*)(?:\xD9\xA4|\xDB\xB4|\xE0\xA5\xAA|\xE0\xA7\xAA|\xE1\x81\x84)(.*)$' $14$2;
rewrite '^(.*)(?:\xD9\xA5|\xDB\xB5|\xE0\xA5\xAB|\xE0\xA7\xAB|\xE1\x81\x85)(.*)$' $15$2;
rewrite '^(.*)(?:\xD9\xA6|\xDB\xB6|\xE0\xA5\xAC|\xE0\xA7\xAC|\xE1\x81\x86)(.*)$' $16$2;
rewrite '^(.*)(?:\xD9\xA7|\xDB\xB7|\xE0\xA5\xAD|\xE0\xA7\xAD|\xE1\x81\x87)(.*)$' $17$2;
rewrite '^(.*)(?:\xD9\xA8|\xDB\xB8|\xE0\xA5\xAE|\xE0\xA7\xAE|\xE1\x81\x88)(.*)$' $18$2;
rewrite '^(.*)(?:\xD9\xA9|\xDB\xB9|\xE0\xA5\xAF|\xE0\xA7\xAF|\xE1\x81\x89)(.*)$' $19$2;
rewrite ^ $uri redirect;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
N.B.: Some browsers could display Eastern Arabic numerals in wrong order because they are RTL characters. Proper order of Eastern Arabic (added LTR override to force it), Western Arabic for comparison: