1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > php 求 相似 比 php计算title标题相似比

php 求 相似 比 php计算title标题相似比

时间:2021-12-10 15:16:55

相关推荐

php 求 相似 比 php计算title标题相似比

采集时常常要对网站内容进行重复判断,php判断正文内容比较困难,对于标题的判断还是比较简单,只要过滤标题中的版权,再用similar_text计算

上代码:

/*

* php计算title标题相似比 by

*

* @param string $title_1 题目1

* @param string $title_2 题目2

* @return float $percent 相似百分比

*/

function title_similar($title_1,$title_2) {

$title_1 = get_real_title($title_1);

$title_2 = get_real_title($title_2);

similar_text($title_1, $title_2, $percent);

return $percent;

}

/**

* php采集文章题目并去版权

* @param string $html 需要采集的html源代码

* @return string

*/

function get_real_title($str){

$str = str_replace(array('-','—','|'),'_',$str);

$splits = explode('_', $str);

$l = 0;

foreach ($splits as $tp){

$len = strlen($tp);

if ($l < $len){$l = $len;$tt = $tp;}

}

$tt = trim(htmlspecialchars($tt));

return $tt;

}

//以下是测试

$title_1 = '代号PHPCMS V9产品正式发布公测版本 - 站长之家';

$title_2 = 'PHPCMS再战江湖 V9产品正式发布公测版本 - 站长网 ';

$percent = title_similar($title_1,$title_2);

echo '相似百分比:'.$percent.'%';

echo "

\n";

?>输出:相似百分比:81.25%

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。