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结合Ffmpeg快速搭建流媒体服务的实践记录

PHP结合Ffmpeg快速搭建流媒体服务的实践记录

一、背景 ffmpeg应该是目前最强大的视频管理程序,当你需要截取视频第一帧,对视频类型进行转换,截取gif图片等一系列对视频的操作,ffmpeg绝对是最好的扩展 笔者想将自己收藏的一些...

php自定义中文字符串截取函数substr_for_gb2312及substr_for_utf8示例

本文实例讲述了php自定义中文字符串截取函数substr_for_gb2312及substr_for_utf8用法。分享给大家供大家参考,具体如下: /* *gb2312中文字符串截...

PHP对象的浅复制与深复制的实例详解

PHP对象的浅复制与深复制的实例详解 最近在看原型模式时注意到这个问题~~PHP中对象 '=' 与‘clone'的区别 实例代码: //聚合类 class ObjA { p...

php 删除cookie方法详解

我们先来看下相关cookie的机制。 复制代码 代码如下: bool setcookie ( string name [, string value [, int expire [, s...

php数组函数序列 之array_count_values() 统计数组中所有值出现的次数函数

array_count_values()定义和用法 array_count_values() 函数用于统计数组中所有值出现的次数。 本函数返回一个数组,其元素的键名是原数组的值,键值是该...