String Comparison - Any Ideas?
Posted: Tue Nov 14, 2006 10:39 pm
I've been brainstorming and writing code and deleting code and essentially going crazy for the past six hours trying to figure out a solution to the following problem. I challenge anyone to help unravel this issue - it'd be greatly appreciated.
Basically, I need a piece of PHP script that will compare two strings and highlight in red what is different in the second vs. the original.
For example:
Original String: I walked the dog. It was fun.
Modified String: Bob walked the cat. He said it was fun.
And the comparison would output the following (with the red, marking the changes):
Compared String: Bob walked the cat. He said it was fun.
Can anyone give me some pointers or actually show me a script that would do this? I've tried it using a combination of some while and for loops, and exploding the strings into arrays. I've somewhat got it, but I can't quite seem to get it right. Any help would be great. Thanks!
Basically, I need a piece of PHP script that will compare two strings and highlight in red what is different in the second vs. the original.
For example:
Original String: I walked the dog. It was fun.
Modified String: Bob walked the cat. He said it was fun.
And the comparison would output the following (with the red, marking the changes):
Compared String: Bob walked the cat. He said it was fun.
Can anyone give me some pointers or actually show me a script that would do this? I've tried it using a combination of some while and for loops, and exploding the strings into arrays. I've somewhat got it, but I can't quite seem to get it right. Any help would be great. Thanks!