-
-
Save Alhamou/70a9807ee79b57ca8d006bf8d19a5877 to your computer and use it in GitHub Desktop.
arsoundex
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 | |
/** | |
this is a simple method , which will return soundex of transliterated arabic string | |
*/ | |
function arSoundex($string) | |
{ | |
// remove any pounctions and any space etc .. | |
$string = preg_replace("/\\p{P}|\\p{M}/u", "" , $string); | |
$chars = array( | |
"ا"=>"أإاآ" , | |
"و"=>"ؤ", | |
"ه"=>"ة", | |
); | |
foreach($chars as $with=>$replace) | |
{ | |
$string = preg_replace("/[{$replace}]/u" , $with , $string); | |
} | |
$string = preg_replace("/ي(?=\Z|\s)/","ى",$string); | |
$latin = [ | |
'ال' => 'EL' , | |
'ا' => 'A', 'ب' => 'B' , 'ت' => 'T', 'ث' => 'T', 'ج' => 'J', | |
'ح' => 'H', 'خ' => 'KH', 'د' => 'D', 'ذ' => 'Z','ر' => 'R', | |
'ز' => 'Z', 'س'=> 'S', 'ش' => 'S', 'ص' => 'S', 'ض' => 'D', | |
'ط' => 'T', 'ظ' => 'Z', 'ع' => 'A', 'غ' => 'G','ف' => 'F', | |
'ق' => 'Q', 'ك' => 'CK','ل' => 'L','م' => 'M','ن' => 'N','ه' => 'H', | |
'و' => 'W', 'ى' => 'Y' | |
]; | |
return soundex(strtr($string , $latin)); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment