CLV. xdiff Functions


xdiff extension creates and applies patches to both text and binary files.


To use xdiff, you will need libxdiff installed, available on the libxdiff homepage

注: You'll need at least libxdiff 0.7 for these functions to be aware of memory_limit.


xdiff is currently available through PECL

If PEAR is available on your *nix-like system you can use the pear installer to install the xdiff extension, by the following command: pear -v install xdiff.

You can always download the tar.gz package and install xdiff by hand:

例子 1. xdiff install by hand

gunzip xdiff-xxx.tgz
tar -xvf xdiff-xxx.tar
cd xdiff-xxx
./configure && make && make install


以下常量由本扩展模块定义,因此只有在本扩展模块被编译到 PHP 中,或者在运行时被动态加载后才有效。



xdiff_file_diff_binary --  Make binary diff of two files
xdiff_file_diff --  Make unified diff of two files
xdiff_file_merge3 --  Merge 3 files into one
xdiff_file_patch_binary --  Patch a file with a binary diff
xdiff_file_patch --  Patch a file with an unified diff
xdiff_string_diff_binary --  Make binary diff of two strings
xdiff_string_diff --  Make unified diff of two strings
xdiff_string_merge3 --  Merge 3 strings into one
xdiff_string_patch_binary --  Patch a string with a binary diff
xdiff_string_patch --  Patch a string with an unified diff

add a note add a note User Contributed Notes
05-Apr-2005 05:09
the xdiff functions require your initial string to end with a \n character.

When you use xdiff_string_diff, the initial string must either be zero-length or end with \n
eg. $patch= xdiff_string_diff($string,$string2);

if not, the patch will return an empty string.

This will not normally affect xdiff_file_diff, but it's annoying nevertheless. To prevent this unexpected effect, I append a \n to the string before applying the initial diff, as follows.
if (!ereg("\n$",$string)) $string.="\n";