Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply Diff in PHP

Tags:

php

diff

patch

pear

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?

like image 540
pschorf Avatar asked Sep 20 '26 11:09

pschorf


1 Answers

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.

like image 157
PEZ Avatar answered Sep 22 '26 23:09

PEZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!