Use PHP to compare string similarity Functions
I wrote this article because I used a DataFeed component when I used joomla a few days ago. The component was very powerful, but the customer asked me to be able to output the relevant products from the feed. This is depressing, if the component does not have this function, you can write the method and modify the component. The method you write at first can be implemented, but the efficiency is low and the response speed is slow. This is depressing, so I searched for "php string similarity" on the Internet. It seems that the Foundation is not solid, as shown below:
The similar_text () function is used to calculate the number of matching characters of two strings. It can also calculate the similarity between the two strings (expressed in percentages ).
<? Php <br/> require ('conn. PHP '); <br/> $ SQL = "select title from content order by ID DESC Limit 20 "; // determine the title similarity <br/> $ result = mysql_query ($ SQL, $ conn); <br/> $ cf = 0; <br/> while ($ ROW = mysql_fetch_array ($ result) {<br/> similar_text ($ row ['title'], $ title, $ percent ); // The comparison similarity is stored in $ percent <br/> if ($ percent> 90) {$ cf = 1; break;} // easy to note: if the similarity is higher than 90%, the query is repeated. <br/>}< br/> if ($ cf = 1) {<br/> echo "<script language = JavaScript> alert ('Sorry! Forbidden to publish duplicate information! '); "; <Br/> echo" this. location. href = 'vbscript: history. back () '; </SCRIPT> "; <br/> mysql_close (); <br/> exit (); <br/>}< br/>?>