Last active
August 17, 2020 08:19
-
-
Save mhf-ir/04a6fc43c8f931b0d0cfa1dc02730c1b to your computer and use it in GitHub Desktop.
alpha_persian_fixer
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 | |
// Characters added via ICU | |
// https://github.com/unicode-cldr/cldr-misc-modern/blob/master/main/fa/characters.json#L10 | |
// | |
// must be duplicate | |
$a = " | |
آابپتثجچهخدذرزژسشصضطظعغفقکگلمنوهیآابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیآاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی | |
"; | |
$b = trim($a); | |
$l = preg_split('//u', $b, -1, PREG_SPLIT_NO_EMPTY); | |
$result = array_map('trim', array_values(array_unique($l, SORT_STRING))); | |
$coll = collator_create( 'fa_IR' ); | |
collator_sort( $coll, $result ); | |
// var_dump($result); | |
foreach ($result as $r) { | |
echo vsprintf("%s %d\n", [ | |
$r, | |
mb_strlen($r), | |
]); | |
}; | |
echo "===========result:\n"; | |
echo implode('', $result) . "\n"; | |
/* | |
آ 1 | |
ا 1 | |
ء 1 | |
أ 1 | |
ؤ 1 | |
ئ 1 | |
ب 1 | |
پ 1 | |
ت 1 | |
ث 1 | |
ج 1 | |
چ 1 | |
ح 1 | |
خ 1 | |
د 1 | |
ذ 1 | |
ر 1 | |
ز 1 | |
ژ 1 | |
س 1 | |
ش 1 | |
ص 1 | |
ض 1 | |
ط 1 | |
ظ 1 | |
ع 1 | |
غ 1 | |
ف 1 | |
ق 1 | |
ک 1 | |
گ 1 | |
ل 1 | |
م 1 | |
ن 1 | |
و 1 | |
ه 1 | |
ة 1 | |
ی 1 | |
===========result: | |
آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment