Php calculates the title similarity ratio, and php calculates the title
This example describes how to calculate the title Similarity Ratio in php. Share it with you for your reference. The details are as follows:
<? Php/*** @ param string $ title_1 Question 1 * @ param string $ title_2 Question 2 * @ return float $ percent similar percentage */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 ;} /*** collect the article title in php and copyright it * @ param string $ html the html source code to be collected * @ return string */function get_real_title ($ str) {$ str = str_replac E (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 ;} // test $ title_1 = 'Code: PHPCMS V9 product officially released Public Beta version'; $ title_2 = 'phpcms then vs. Jianghu V9 product 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 php programming.