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

相关文章

加强版phplib的DB类

复制代码 代码如下:<?php /*************************************************************************...

php 移除数组重复元素的一点说明

如:复制代码 代码如下:$test_array=array(1,2,3,4,4,5,5,6); $test_array_unique=array_unique($test_array);...

PHP中的错误处理、异常处理机制分析

例: 复制代码 代码如下: <?php $a = fopen('test.txt','r'); //这里并没有对文件进行判断就打开了,如果文件不存在就会报错 ?> 那么正确...

介绍一些PHP判断变量的函数

虽然这一特点使用PHP编程非常容易,但它也存在一个重要的缺陷:当你需要测试一个变量的类型时,处理类型比较松散的语言就让人有些迷惑。幸运地是,PHP的开发者注意到这一情况,因此在其中包含了...

PHP使用反向Ajax技术实现在线客服系统详解

PHP使用反向Ajax技术实现在线客服系统详解

本文实例讲述了PHP使用反向Ajax技术实现在线客服系统。分享给大家供大家参考,具体如下: 反向Ajax技术,又称为服务器推技术,server push等。一般用于“在线客服”、“消息推...