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中CURL方法curl_setopt()函数的参数分享

PHP CURL curl_setopt 参数bool curl_setopt (int ch, string option, mixed value)curl_setopt()函数将为...

详解PHP的Yii框架中自带的前端资源包的使用

Yii中的资源是和Web页面相关的文件,可为CSS文件,JavaScript文件,图片或视频等, 资源放在Web可访问的目录下,直接被Web服务器调用。 通过程序自动管理资源更好一点,例...

php之curl设置超时实例

本文实例讲述了php中curl超时设置方法。分享给大家供大家参考。具体实现方法如下: 访问HTTP方式很多,可以使用curl, socket, file_get_contents() 等...

php中使用websocket详解

在PHP中,开发者需要考虑的东西比较多,从socket的连接、建立、绑定、监听等都需要开发者自己去操作完成,对于初学者来说,难度方面也挺大的,所以本文的思路如下: 1、socket协议的...

PHP数学运算与数据处理实例分析

本文实例讲述了PHP数学运算与数据处理方法。分享给大家供大家参考,具体如下: 一.数值数据类型 PHP中,数字或数值数据以及数学函数的使用很简单。基本来说,要处理两种数据类型:浮点数和...