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实现的pdo连接数据库并插入数据功能简单示例

本文实例讲述了PHP实现的pdo连接数据库并插入数据功能。分享给大家供大家参考,具体如下: 创建配置文件 pdo_config.php <?php $db_Type...

php使用strip_tags()去除html标签仍有空白的解决方法

本文实例讲述了php使用strip_tags()去除html标签仍有空白的解决方法。分享给大家供大家参考,具体如下: $subject = strip_tags($newsRs['c...

PHP模型Model类封装数据库操作示例

本文实例讲述了PHP模型Model类封装数据库操作。分享给大家供大家参考,具体如下: <?php //引入配置文件 include "./config.php"...

PHP中file_put_contents追加和换行的实现方法

在PHP的一些应用中需要写日志或者记录一些信息,这样的话。可以使用fopen(),fwrite()以及 fclose()这些进行操作。也可以简单的使用file_get_contents(...

刚才在简化php的库,结果发现很多东西

php的ming库用来生成flash!虽然模块是试验性质的, 不过比较有趣。一张大大的表, 很有趣, 给人一种在8g的感觉。 sapi/php4activescript.dll (p...