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获取用户的浏览器与操作系统信息的代码

1.用户访问服务器时,利用PHP的超级全局变量$_SERVER数组中字段['HTTP_USER_AGENT'] 获取访问用户的所有信息 我访问时的$_SERVER['HTTP_USER_...

php获取从百度搜索进入网站的关键词的详细代码

分享一个php获取从百度搜索进入网站的关键词的代码,有需要的朋友可以参考一下: 代码: 复制代码 代码如下: <?php function search_word_from() {...

php 验证码制作(网树注释思想)

1,生成随机数 用for循环确定生成几个随机数。 用随机函数生成范围内随机数。例如rand(1,15),生成1到15之间的数字。 用16位进制函数把生成数字字母化。dechex(rand...

php中preg_replace_callback函数简单用法示例

本文实例讲述了php中preg_replace_callback函数用法。分享给大家供大家参考,具体如下: mixed preg_replace_callback ( mixed pat...

PHP带节点操作的无限分类实现方法详解

本文实例讲述了PHP带节点操作的无限分类实现方法。分享给大家供大家参考,具体如下: 包含(移动多个节点;移动单个节点;删除多个节点;删除单个节点;新增节点),另附数据库表结构 一、db...