Home  >  Article  >  php教程  >  php similar_text()函数的定义和用法,phpsimilar_text

php similar_text()函数的定义和用法,phpsimilar_text

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

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+

 

实例

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

<&#63;phpsimilar_text("Hello World","Hello Shanghai",$percent);echo $percent. "%";&#63;>

以上这篇php similar_text()函数的定义和用法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持帮客之家。

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