PHP similar_text() 函数

PHP 教程 · 2019-01-29 21:28:52

实例

计算两个字符串的相似度并返回匹配字符的数目:

<?php
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;
?>

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Mastering Bitcoin

Mastering Bitcoin

Andreas M. Antonopoulos / O'Reilly Media / 2014-12-20 / USD 34.99

Mastering Bitcoin tells you everything you need to know about joining one of the most exciting revolutions since the invention of the web: digital money. Bitcoin is the first successful digital curren......一起来看看 《Mastering Bitcoin》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

SHA 加密
SHA 加密

SHA 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具