Home > php教程 > php手册 > body text

PHP计算两个字符的相似程度similar_text,phpsimilar_text

WBOY
Release: 2016-06-13 08:51:32
Original
878 people have browsed it

PHP计算两个字符的相似程度similar_text,phpsimilar_text

在网站开发中,我们会常常要计算两个字符的相似程度,那么PHP为我们提供了一个函数similar_text;

    

 

    1,similar_text的用法

    如果我想计算"ly89cn"和"ly89"的相似程度,有两种表示方法

echo similar_text('ly89cn', 'ly89');
Copy after login

这样输出4,因为他们有4个字符相等

similar_text('ly89cn', 'ly89', $percent<span>);
echo $percent;</span>
Copy after login

这样输出80,$percent代表百分比,说明他们有80%的相似程度

当然也可以比较两个中文字符,比如“王业楼的个人博客”和“王业楼”

echo similar_text('王业楼的个人博客', '王业楼');
Copy after login

这样输出9,表示他们的9个字节数相等

similar_text('王业楼的个人博客', '王业楼', $percent<span>);
echo $percent;</span>
Copy after login

     输出54.545454545455,注意中文字符可能不大准确!

    2,网站相关博文的设计

    一般网站都会在一篇文章下方推荐几篇相似文章,那么我们就可以用similar_text这个函数来设计!将文章的标题与网站已有文章的标题比较,按照相似度由高到低的顺序找到一定数量的文章然后放到你相关文章的内容中!

 

想要每天及时获取王业楼的个人博客更新的内容吗?赶快添加微信公众号“ly89cn”,或者扫描下方的二维码吧!

 

本文来源于王业楼的个人博客,本文地址:http://www.ly89.cn/detailB/58.html

欢迎分享本文,转载请注明本文出处和地址

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!