php比较相似字符串的方法

平缓的、山坡上镶嵌着一块块粉红色的荞麦田,路边铺着碧绿的青稞地,圆木建成的围栏顺着弯弯曲曲的土路,一直通向远方的原始森林,藏式吊脚楼错落有致地分布在路旁,煮奶茶的淡蓝色烟雾中,牛群、羊群时隐时现,整个氛围呈现着一种中世纪乡土意味。

本文实例讲述了php比较相似字符串的方法。分享给大家供大家参考。具体分析如下:

这里通过php的similar_text函数比较两个字符串的相似性。

$word2compare = "stupid";
$words = array(
  'stupid',
  'stu and pid',
  'hello',
  'foobar',
  'stpid',
  'upid',
  'stuuupid',
  'sstuuupiiid',
);
while(list($id, $str) = each($words)){
  similar_text($str, $word2compare, $percent);
  print "Comparing '$word2compare' with '$str': ";
  print round($percent) . "%\n";
}
/*
Results:
Comparing 'stupid' with 'stupid': 100%
Comparing 'stupid' with 'stu and pid': 71%
Comparing 'stupid' with 'hello': 0%
Comparing 'stupid' with 'foobar': 0%
Comparing 'stupid' with 'stpid': 91%
Comparing 'stupid' with 'upid': 80%
Comparing 'stupid' with 'stuuupid': 86%
Comparing 'stupid' with 'sstuuupiiid': 71%
*/

希望本文所述对大家的php程序设计有所帮助。

到此这篇关于php比较相似字符串的方法就介绍到这了。生命之舟面对险滩,面对激流,弱者会选择逃避和放弃,而强者则会选择面对和挑战。人生中无限的乐趣都在于对人生的挑战之中迸出不衰的光芒。更多相关php比较相似字符串的方法内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
PHP性能优化案例分享

PHP实现短信验证码的发送次数限制

PHP中的异常处理机制深入讲解

PHP常见七种算法合集代码实例

PHP微信扫描二维码关注公众号后自动登录第三方网站