php计算title标题相似比的方法,php计算title标题_PHP教程

WBOY
Release: 2016-07-13 09:45:41
Original
747 people have browsed it

php计算title标题相似比的方法,php计算title标题

本文实例讲述了php计算title标题相似比的方法。分享给大家供大家参考。具体如下:

<&#63;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 = '代号PHPCMS V9产品正式发布公测版本';
$title_2 = 'PHPCMS再战江湖 V9产品正式发布公测版本';
$percent = title_similar($title_1,$title_2);
echo '相似百分比:'.$percent.'%';
echo "<br />\n";
&#63;>
Copy after login

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1039206.htmlTechArticlephp计算title标题相似比的方法,php计算title标题 本文实例讲述了php计算title标题相似比的方法。分享给大家供大家参考。具体如下: php /*...
Related labels:
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 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!