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

yipeiwu_com5年前PHP代码库

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

<?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";
?>

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

相关文章

PHP中通过加号合并数组的一个简单方法分享

代码: 复制代码 代码如下: <?php $a = array('a' => 'a', 'b' => 'b'); $b = array('c' => 'c', '...

PHP面向对象程序设计之类常量用法实例

类常量是PHP面向对象程序设计中非常重要的一个概念,牢固掌握类常量有助于进一步提高PHP面向对象程序设计的水平。本文即以实例形式描述了PHP程序设计中类常量的用法。具体如下: 类常量:类...

CodeIgniter php mvc框架 中国网站

我们很高兴的宣布 CodeIgniter 1.6.2 版正式发布。本次发布包括超过 29 个 BUG 修复和&nbs...

PHP与SQL注入攻击[二]

PHP与SQL注入攻击[二] Magic Quotes 上文提到,SQL注入主要是提交不安全的数据给数据库来达到攻击目的。为了防止SQL注 入攻击,PHP自带一个功能可以对输入...

用PHP的ob_start();控制您的浏览器cache!

【转载】原文地址:http://www.itbbs.cn/index.php?showtopic=1074    Output Control 函数可以让你自由控制脚...