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

相关文章

discuz目录文件资料汇总

在某处收集来的discuz目录资料,二次开发挺有用的。记录下。(基于7.0的标准程序,部分与插件无关的文件不作说明) 文件颜色说明: 红色:程序核心文件,修改这类文件时千万要注意安全!...

使用PHP求两个文件的相对路径

复制代码 代码如下:function compare($ph1,$ph2){    $ret = '';    $_f1Arr...

深入解析PHP的Yii框架中的event事件机制

事件 事件可以将自定义代码“注入”到现有代码中的特定执行点。附加自定义代码到某个事件,当这个事件被触发时,这些代码就会自动执行。例如,邮件程序对象成功发出消息时可触发 messageSe...

PHP文件下载类

复制代码 代码如下:<?    //==================================================== ...

PHP简单实现上一页下一页功能示例

本文实例讲述了PHP简单实现上一页下一页功能。分享给大家供大家参考,具体如下: 思路整理: 现在好多人用id的增1和减1实现上一篇和下一篇,但是难道文章ID不会断了吗?所以你要知道上个I...