Skip to content

Instantly share code, notes, and snippets.

@ahmadmarafa
Last active September 2, 2021 17:58
Show Gist options
  • Save ahmadmarafa/8cfe27839623bf2b6b96e089a4b6fbdb to your computer and use it in GitHub Desktop.
Save ahmadmarafa/8cfe27839623bf2b6b96e089a4b6fbdb to your computer and use it in GitHub Desktop.

Revisions

  1. ahmadmarafa renamed this gist Sep 2, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. ahmadmarafa revised this gist Jan 28, 2019. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -17,12 +17,13 @@ function arSoundex($string)
    }
    $string = preg_replace("/ي(?=\Z|\s)/","ى",$string);
    $latin = [
    'ا' => 'A', 'ب' => 'B' , 'ت' => 'T', 'ث' => 'T', 'ج' => 'J',
    'ح' => 'H', 'خ' => 'K', 'د' => 'D', 'ذ' => 'Z','ر' => 'R',
    'ز' => 'Z', 'س' => 'S', 'ش' => 'S', 'ص' => 'S', 'ض' => 'D',
    'ط' => 'T', 'ظ' => 'Z', 'ع' => 'A', 'غ' => 'G','ف' => 'F',
    'ق' => 'Q','ك' => 'K','ل' => 'L','م' => 'M','ن' => 'N','ه' => 'H',
    'و' => 'W','ي' => 'Y'
    'ال' => '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));
  3. ahmadmarafa renamed this gist Feb 13, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. ahmadmarafa created this gist Feb 13, 2018.
    30 changes: 30 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    <?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 = [
    'ا' => 'A', 'ب' => 'B' , 'ت' => 'T', 'ث' => 'T', 'ج' => 'J',
    'ح' => 'H', 'خ' => 'K', 'د' => 'D', 'ذ' => 'Z','ر' => 'R',
    'ز' => 'Z', 'س' => 'S', 'ش' => 'S', 'ص' => 'S', 'ض' => 'D',
    'ط' => 'T', 'ظ' => 'Z', 'ع' => 'A', 'غ' => 'G','ف' => 'F',
    'ق' => 'Q','ك' => 'K','ل' => 'L','م' => 'M','ن' => 'N','ه' => 'H',
    'و' => 'W','ي' => 'Y'
    ];

    return soundex(strtr($string , $latin));
    }
    ?>