php比较相似字符串的方法

yipeiwu_com5年前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中foreach/in_array的使用

php在开发效率很高,这是无可厚非的,但是却是在牺牲执行效率的。php数组功能非常强大,但是也要多加考虑,多试几种情况情况,以防万一,这里,我就简单的说两个遇到的坑,以后如果有发现更多的...

PHP利用Socket获取网站的SSL证书与公钥

通过 php curl 请求网页并不能获取到证书信息,此时需要使用 ssl socket 获取证书内容。下面来一起看看看详细的介绍: 示例代码: // 创建 stream conte...

Linux下CoreSeek及PHP扩展模块的安装

本人安装CoreSeek的系统为Centos6.0  CoreSeek版本: coreseek 3.2.14:点击下载   PHP:PECL/Sphinx扩...

PHP异步进程助手async-helper

简介 PHP 的异步进程助手,借助于 AMQP 实现异步执行 PHP 的方法,将一些很耗时、追求高可用、需要重试机制的操作放到异步进程中去执行,将你的 HTTP 服务从繁重的业务逻辑中...

使用php实现截取指定长度

PHP语言: 根据中文裁减字符串复制代码 代码如下:function cutstr($string,$length, $dot = ' ...') {  if (strlen(...