Apply Diff in PHP

2020-07-22 03:28发布

问题:

I'm working with the Text_Diff PEAR package to diff to short text documents, where the Text_Diff object is created with a space-delimited list of the words in each document. I was hoping to store the diff in a database, and then apply it when the file is loaded again. Is there an easy way to apply this diff, or do I need to write a function to parse it?

回答1:

The php xdiff extension supports patching from both files and strings. Looking at the source for Text_Diff I see that it uses xdiff for performing the diffs. You should be able to patch using xdiff_string_patch() or some of it's sibling functions.