嘿伙计:)我想问一些解决方案.现在,我有字典words.txt,这里有一些例子:
happy
laugh
sad
Run Code Online (Sandbox Code Playgroud)
我有俚语字符串:
hppy
Run Code Online (Sandbox Code Playgroud)
我想搜索并匹配那个俚语字符串到我的字典,这意味着它会返回"happy",因为那些字符串在字典中引用"happy".
最近我一直在使用similar_text(),但对其有效性没有信心.你们能为我的问题推荐更好的解决方案吗?谢谢 :)
在这里我把我的代码:
function searchwords($tweet){
//echo $tweet;
$find = false;
$handle = @fopen("words.txt", "r");
if ($handle)
{
while (!feof($handle))
{
$buffer = fgets($handle);
similar_text(trim($tweet),trim($buffer),$percent);
if ($percent == 100){ // this exact match
$find = true;
}else if ($percent >= 90){ //there is the possibility of errors
$find = true;
}
}
fclose($handle);
}
if ($find == true){
unset($tweet); …Run Code Online (Sandbox Code Playgroud)