星期五, 8月 05, 2011

php比較相似字串

  1. 比對相似的字串 similar_text($str1, $str2)
    //測試性名陣列
    $names = array('Robert Smith','Bobby Smythe','Roberto Thithe', 'Robin Smith');

    //檢查相似程度
    foreach($names as $name){
    similar_text($name, 'Roberto Smythi', $percent);
    echo "{$name} = {$percent}%\n";
    }
    //result
    //Robert Smith = 88%
    //Bobby Smythe = 64%
    //Roberto Thithe = 74.074074074074%
    //Robin Smith' = 66.66666666667%
  2. levenshtei()


See Also

  • soundex() - Calculate the soundex key of a string

沒有留言: