PHP calculates the title similarity ratio method, PHP calculates title title
In this paper, we describe the method of calculating the similarity ratio of title titles in PHP. Share to everyone for your reference. Specific as follows:
<?php/* * * @param string $title _1 Topic 1 * @param string $title _2 topic 2 * @return float $percent similar percentage */function title_si Milar ($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 collects the article title and goes to copyright * @param string $html The HTML source code to be collected * @return string */function get_real_title ($str) { $str = str_re Place (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 product officially released public beta version '; $title _2 = ' phpcms re-war Lake V9 product officially released beta '; $percent = Title_similar ($title _1,$ title_2); Echo ' similarity percent: '. $percent. ' % '; Echo '
\ n ";? >
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1039206.html www.bkjia.com true http://www.bkjia.com/PHPjc/1039206.html techarticle php calculate Title Title similarity Ratio method, PHP calculate title title in this paper, we describe the method of calculating the similarity ratio of title titles in PHP. Share to everyone for your reference. as follows: PHP/* ...