找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1643|回复: 0
打印 上一主题 下一主题

php比较相似字符串的方法

[复制链接]

3444

主题

3465

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
11142
跳转到指定楼层
楼主
发表于 2018-2-14 05:45:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            本文实例讲述了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常用字符串比较函数实例汇总
  • 关于php几种字符串连接的效率比较(详解)
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端