views:

143

answers:

4

Like the title, How to compare text?. For a example, go to textdiff.com.

+4  A: 

Check out Levenshtein distance. This is a fairly general algorithm for identifying differences between two strings.

JoshD
No, i want to ask the algorithm. Not a software. But it is good if you give me a php class
Snoob
PHP has a `levenshtein()` function you can look into.
Russell Dias
Levensthein measures the "amount of difference" between two strings, but will not return the location of the differences. Also, I am not sure how useful it is for comparing sentences. `Text_Diff` will do exactly what the OP asked for (see my answer for links)
nico
+1  A: 

You may want to have a look at Pear's Text_Diff

http://pear.php.net/package/Text_Diff/

nico
Is there a php class
Snoob
@Snoob: Yes, `Text_Diff` is one of the classes of the Pear framework. You will have to install the base Pear components first (see http://pear.php.net/manual/en/installation.introduction.php ) and, once that is working you can add Text_Diff. Looking at the page you linked I would say that's what they used. `Text_Diff` comes with documentation and examples: http://pear.php.net/package/Text_Diff/docs/latest/
nico
A: 

if you're looking for a terminal command, check out diff, found in linux by default. You can also have it on windows by installing cygwin [with a LOT of excess baggage. :\ ]

Karthick