dongxin2734 2016-07-01 02:25
浏览 75

比较两个字符串与PHP之间的相似性

Hey guys :) I want to ask for some solution. Now, I have dictionary words.txt, here some example:

happy
laugh
sad

And I have the slang string:

hppy

I want to search & match that slang string to my dictionary wich means it will return "happy" because those string refer to "happy" in dictionary.

Recently I've been using similar_text() but doesn't confident about its validity. Can you guys recommend better solution for my problem? Thank you :)

And here i put my codes:

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);
  }else{
    return $tweet;
  }
}
  • 写回答

2条回答 默认 最新

  • dongyi2159 2016-07-01 03:18
    关注

    Hopefully it'll serve your purpose. But there are some things to keep in mind while working with similar_text().

    1. matching percentage can differ depending on the order of parameters. ie: similar_text($a, $b, $percent) and similar_text($b, $a, $percent) here in both cases $percent may not be same.
    2. Note that this function is case sensitive: so while passing $a and $b pass both either in uppercase or lowercase.

    for more info check this page

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度