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://www.codercto.com/courses/l/5.html

查看所有标签

Beginning ARKit for iPhone and iPad

Beginning ARKit for iPhone and iPad

Wallace Wang / Apress / 2018-11-5 / USD 39.99

Explore how to use ARKit to create iOS apps and learn the basics of augmented reality while diving into ARKit specific topics. This book reveals how augmented reality allows you to view the screen on ......一起来看看 《Beginning ARKit for iPhone and iPad》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器