Using PHP to compare string similarity functions, joomla DataFeed

Source: Internet
Author: User
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/>?>

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.