Home  >  Article  >  php教程  >  php计算title标题相似比

php计算title标题相似比

WBOY
WBOYOriginal
2016-06-07 11:45:121267browse

采集时常常要对网站内容进行重复判断,php判断正文内容比较困难,对于标题的判断还是比较简单,只要过滤标题中的版权,再用similar_text计算
<?php <br /> /*<br>  * php计算title标题相似比 by enenba.com<br>  *<br>  * @param string $title_1 题目1<br>  * @param string $title_2 题目2<br>  * @return float $percent 相似百分比<br>  */<br> function title_similar($title_1,$title_2) {<br>     $title_1 = get_real_title($title_1);<br>     $title_2 = get_real_title($title_2);<br>     similar_text($title_1, $title_2, $percent);<br>     return $percent;<br> }<br> /**<br>  * php采集文章题目并去版权<br>  * @param string  $html  需要采集的html源代码<br>  * @return string<br>  */<br> <br> function get_real_title($str){<br>     $str = str_replace(array('-','—','|'),'_',$str);<br>     $splits = explode('_', $str);<br>     $l = 0;<br>     foreach ($splits as $tp){<br>         $len = strlen($tp);<br>         if ($l      }<br>     $tt = trim(htmlspecialchars($tt));<br>     return $tt;<br> }<br> <br> <br> //以下是测试<br> $title_1 = '代号PHPCMS V9产品正式发布公测版本 - 站长之家';<br> $title_2 = 'PHPCMS再战江湖 V9产品正式发布公测版本 - 站长网 admin5.com';<br> $percent = title_similar($title_1,$title_2);<br> echo '相似百分比:'.$percent.'%';<br> echo "<br>\n";<br> <br> ?> http://blog.ddian.cn/?post=874

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
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
Previous article:公共模块禁止直接访问Next article:自定义UBB的实现