简体   繁体   中英

MYSQL find how different two text fields are?

I'm storing the HTML content of emails in my database.

If I store two of the same emails in my database, that are only a little different because of personalization (one might say "Hello Stephen, thank you for subscribing...", and the other "Hello Andrew, thank you for subscribing...").

How can I tell that these text fields are only slightly different? (maybe get a percentage saying they're 95% alike).

Here's a good starting point for MySQL: http://www.artfulsoftware.com/infotree/queries.php#552

A Levenshtein distance is the number of edits required to turn one string into another. You could probably mess with dividing that distance by the length of the string to get a percentage of sorts.

For PHP, there is a builtin Levenshtein function: http://www.php.net/manual/en/function.levenshtein.php

This could also help: http://www.php.net/manual/en/function.similar-text.php . similar_text() returns the number of matching chars in both strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM