PHP similar_text() 函数
PHP 教程
· 2019-01-29 21:28:52
实例
计算两个字符串的相似度并返回匹配字符的数目:
<?php
echo similar_text("Hello World","Hello Peter");
?>
echo similar_text("Hello World","Hello Peter");
?>
定义和用法
similar_text() 函数计算两个字符串的相似度。
该函数也能计算两个字符串的百分比相似度。
注释:levenshtein() 函数比 similar_text() 函数更快。不过,similar_text() 函数通过更少的必需修改次数提供更精确的结果。
语法
similar_text(string1,string2,percent)
| 参数 | 描述 |
|---|---|
| string1 | 必需。规定要比较的第一个字符串。 |
| string2 | 必需。规定要比较的第二个字符串。 |
| percent | 可选。规定供存储百分比相似度的变量名。 |
技术细节
| 返回值: | 返回两个字符串的匹配字符的数目。 |
|---|---|
| PHP 版本: | 4+ |
更多实例
实例 1
计算两个字符串的百分比相似度:
<?php
similar_text("Hello World","Hello Peter",$percent);
echo $percent;
?>
similar_text("Hello World","Hello Peter",$percent);
echo $percent;
?>
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Automate This
Christopher Steiner / Portfolio / 2013-8-9 / USD 25.95
"The rousing story of the last gasp of human agency and how today's best and brightest minds are endeavoring to put an end to it." It used to be that to diagnose an illness, interpret legal docume......一起来看看 《Automate This》 这本书的介绍吧!