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中使用sftp教程

<?php /** php 中的sftp 使用教程 Telnet、FTP、SSH、SFTP、SSL (一) ftp 协议简介 FTP(File Tran...

PHP常用的缓存技术汇总

一、数据缓存 这里所说的数据缓存是指数据库查询缓存,每次访问页面的时候,都会先检测相应的缓存数据是否存在,如果不存在,就连接数据库,得到数据,并把查询结果序列化后保存到文件中,以后同样的...

PHP入门教程之字符串处理技巧总结(转换,过滤,解析,查找,截取,替换等)

本文实例总结了PHP字符串处理技巧。分享给大家供大家参考,具体如下: Demo1.php <?php //源代码是文本形式,页面显示是 web 形式 $str...

PHP网站备份程序代码分享

PHP网站备份程序代码分享

效果图:PHP代码 复制代码 代码如下: <html> <head> <meta http-equiv="Content-Type" content="te...