php比较相似字符串的方法

yipeiwu_com5年前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程序设计有所帮助。

相关文章

header与缓冲区之间的深层次分析

测试header之前有输出 <?php echo 'hello world!'; header('content-type: text/html;charset=ut...

微信 开发生成带参数的二维码的实例

微信开发生成带参数的二维码的讲解 在微信公众号平台开发者那里,在“账号管理”那里,有一项功能是“生成带参数的二维码”,通过这儿生成的二维码,只要通过微信扫一扫之后,会把事件自动推送到微...

php报错502badgateway解决方法

目前lnmp一键安装包比较多的问题就是502 Bad Gateway,大部分情况下原因是在安装php前,脚本中某些lib包可能没有安装上,造成php没有编译安装成功。 解决办法:可以尝试...

PHP管理内存函数 memory_get_usage()使用介绍

下面是PHP memory_get_usage()使用示例: 复制代码 代码如下: echo memory_get_usage(), '<br />'; //143952 $...

轻松修复Discuz!数据库

轻松修复Discuz!数据库

那么使用下面的方法,就有可能修复轻松修复数据库。您的站点地址admincp.php 访问系统后台 = 系统工具 = 数据库 =...