php计算title标题相似比
php计算title标题相似比 [代码片段(41行)]
<?php
/*
*
* @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 = 'json 与java对象转换 - 代码片段 - CodeSnippet.cn';
$title_2 = 'java对象转换类型转换 - 代码片段 - CodeSnippet.cn';
$percent = title_similar($title_1,$title_2);
echo '相似百分比:'.$percent.'%';
echo "<br />\\n";
?>
//该片段来自于http://outofmemory.cn
- 上一篇:php检查用户名是否符合规定
- 下一篇:创建文件 php创建一个简单的文本文件
精彩图集
精彩文章






