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数组实现无限分类,不使用数据库,不使用递归.

复制代码 代码如下:<?php class cat {     public $data;   &n...

php获取文件类型和文件信息的方法

本文实例讲述了php获取文件类型和文件信息的方法。分享给大家供大家参考。具体实现方法如下: <?php $file = "php.txt"; //打开文件,r表示以只读...

详解json在php中的应用

从5.2版本开始,PHP原生提供json_encode()和json_decode()函数,前者用于编码,后者用于解码。 一、json_encode() 该函数主要用来将数组和对象,转换...

PHP 文件上传后端处理实用技巧方法

PHP 文件上传后端处理实用技巧方法 引语:在上一篇文章中说到,在页面中可以用隐藏的方式让你的上传页面看起来漂亮。但是这对于性能来说,并没有什么卵用,那么在后台的处理中,难道就没有一些处...

PHP函数实现分页含文本分页和数字分页

PHP函数实现分页含文本分页和数字分页

最近,在项目中要用到分页。分页功能是经常使用的一个功能,所以,对其以函数形式进行了封装。 // 分页分装 /** * $pageType 分页类型 1是数字分页 2是文本分页 * 可...