PHP Computing Title Title similarity Ratio Method _php skill

Source: Internet
Author: User

This article illustrates the method of PHP to calculate title title similarity ratio. Share to everyone for your reference. Specifically as follows:

<?php 
/
 * *
 @param string $title _1 topic 1
 * @param string $title _2 Title 2
 * @return Similar percentage of 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 collect article title and copyright
 * @param string $html The HTML source code to be collected
 * @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;
}
The following is the test
$title _1 = ' Code PHPCMS V9 products officially released public beta version ';
$title _2 = ' Phpcms V9 products officially released public beta version ';
$percent = Title_similar ($title _1, $title _2);
echo ' similar percentage: '. $percent. ' %';
echo "<br/>\n";
? >

I hope this article will help you with your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.