views:

66

answers:

2

Hi all!

Say, I have var1 and var2 both with a string value. Var2 is a revision of var1 with minor changes: var1:

Hello, world1

var2:

Bye bye, world!

Now I want this output:

<span class="removed">Hello</span> <span class="new">Bye bye</span>, world<span class="removed">1</span><span class="new">!</span>

much like SO's way. How can I do this in php?

Thanks

+2  A: 

I would suggest you take a look at Text_Diff on PEAR.

Sebastian P.
It says 404
Time Machine
Seems to be a bad link, try http://pear.php.net/package/Text_Diff
Cal Jacobson
Fixed....seems like the "a href" syntax works, but the other syntaxes encode the underscore.
JW
I'll take a look at it.
Time Machine
A: 

Longest common subsequence problem. Once I found nice implementation in Python and translated it into PHP (because PHP arrays are quite memory expensive I had to sacrifice speed by using string to hold LCS matrix).

Jakub Kulhan