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
Thinking Recursively
Eric S. Roberts / Wiley / 1986-1-17 / USD 85.67
The process of solving large problems by breaking them down into smaller, more simple problems that have identical forms. Thinking Recursively: A small text to solve large problems. Concentrating on t......一起来看看 《Thinking Recursively》 这本书的介绍吧!