Home  >  Article  >  php教程  >  php similar_text(),phpsimilar_text

php similar_text(),phpsimilar_text

WBOY
WBOYOriginal
2016-06-13 08:40:28889browse

php similar_text(),phpsimilar_text

php similar_text() 函数计算比较两个字符串的相似度,本文章向码农介绍php similar_text() 函数的基本使用方法和基本使用实例,感兴趣的码农可以参考一下。

定义和用法

similar_text() 函数计算两个字符串的相似度。

该函数也能计算两个字符串的百分比相似度。

注释:levenshtein() 函数比 similar_text() 函数更快。不过,similar_text() 函数通过更少的必需修改次数提供更精确的结果。

 

语法

similar_text(string1,string2,percent)

  

参数 描述
string1 必需。规定要比较的第一个字符串。
string2 必需。规定要比较的第二个字符串。
percent 可选。规定供存储百分比相似度的变量名。

 

技术细节

返回值: 返回两个字符串的匹配字符的数目。
PHP 版本: 4+

 

实例

计算两个字符串之间的百分比相似度:

<?<span>php
</span><span>similar_text</span>("Hello World","Hello Shanghai",<span>$percent</span><span>);
</span><span>echo</span> <span>$percent</span>. "%"<span>;
</span>?>

在线运行

 

原文地址:http://www.manongjc.com/article/805.html

 

php相关学习:

  • php运算符
  • php表达式
  • PHP循环控制
  • PHP流程控制
  • php数组
  • php函数
  • php全局变量
  • PHP魔术变量
  • php命名空间
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn