php比较相似字符串的方法

yipeiwu_com6年前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实现网页内容html标签补全和过滤的方法小结【2种方法】

本文实例讲述了PHP实现网页内容html标签补全和过滤的方法。分享给大家供大家参考,具体如下: 如果你的网页内容的html标签显示不全,有些表格标签不完整而导致页面混乱,或者把你的内容之...

php+ajax实时刷新简单实例

本文实例讲述了php+ajax实时刷新简单实现方法,分享给大家供大家参考。具体如下: ajax自动刷新好像是个很常见的问题,之前做一个网页聊天室程序也是卡在了这上面,经过了这段时间的学习...

PHP读取xml方法介绍

一,什么是xml,xml有什么用途   XML(Extensible Markup Language)即可扩展标记语言,它与HTML一样,都是SGML(Standard Generali...

PHP的RSA加密解密方法以及开发接口使用

网络安全问题很重要,尤其是保证数据安全,遇到很多在写接口的程序员直接都是明文数据传输,在我看来这是很不专业的。本人提倡经过接口的数据都要进行加密解密之后进行使用。 这篇文章主要介绍使用P...

图文介绍PHP添加Redis模块及连接

图文介绍PHP添加Redis模块及连接

下面通过图文并茂的方式给大家展示如下: 上几篇文章介绍了Redis的安装及使用,下面将介绍php如何添加Redis扩展!   php手册并没有提供Redis的类和方法,也没有提供相关的扩...