Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alhamou/70a9807ee79b57ca8d006bf8d19a5877 to your computer and use it in GitHub Desktop.
Save Alhamou/70a9807ee79b57ca8d006bf8d19a5877 to your computer and use it in GitHub Desktop.
arsoundex
<?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