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.