在PHP或mySQL中减去两个字符串来计算差异[重复]

This question already has an answer here:

Is it possible to return the number of characters which differ between two strings?

In my case, I would like to run a check to quantify how much a user's draft has changed vs the database version. With this information, the system can decide weather or not the draft needs to be auto-saved.

For example:

echo string_diff("Hello world", "Hi World");

This should output "5", indicating that characters "ello" & "W" are different.

Is this possible with PHP? How about with mySQL?

</div>

On the PHP side your options are

  1. similar_text which calculates the percent similarity between two strings
  2. levenshtein - which calculates the edit distance between two strings (the number of key strokes it takes to transform string a into string b)

on mysql you can use this user defined function to calculate the levenshtein distance