0

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?

3

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.