开发者

PHP: Wiki style before/after edit comparisons of text

Say I had 2 paragraphs of text to comp开发者_JAVA技巧are..

1) "Text text text text text
text text text text text
text text text text text"

2) "Text text text text text
text text text NEW TEXT text text
text text text text text"

How would I go about finding out what the different parts are from the first paragraph to the next (like what you see in wiki edits)? My only guess would be to explode() each paragraph by "\n" and do a line by line comparison, but I'm sure there is much more to it


There's a PEAR library for doing textual diffs that should help instead of reinventing the wheel:

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


Er, I should've done this sooner, but apparently pastebin.com is open source and on their site is their code is hosted. I peered into it and saw that they were using this: http://www.holomind.de/phpnet/diff2.src.php


You can use a tool such as diff

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜