xdiff_file_patch
xdiff_file_patch
Patch a file with an unified diff
mixed **xdiff_file_patch** string $file string $patch string $dest int $flags
Patches a with a and stores the result in a file.
has to be an unified diff created by
/ function.
An optional parameter specifies mode of operation.
file``patch``patch``xdiff_file_diff``xdiff_string_diff``flags
fileThe original file.
patch
The unified patch file. It has to be created using ,
functions or compatible tools.
xdiff_string_diff``xdiff_file_diff
destPath of the resulting file.
flags
Can be either (default mode,
normal patch) or (reversed
patch).
XDIFF_PATCH_NORMAL``XDIFF_PATCH_REVERSE
Starting from version 1.5.0, you can also use binary OR to enable
flag.
`XDIFF_PATCH_IGNORESPACE`
Returns false if an internal error happened, string with rejected chunks if patch couldn't be applied or true if patch has been successfully applied.
Voorbeeld: example
The following code applies unified diff to a file.
<?php
$old_version = 'my_script-1.0.php';
$patch = 'my_script.patch';
$errors = xdiff_file_patch($old_version, $patch, 'my_script-1.1.php');
if (is_string($errors)) {
echo "Rejects:\n";
echo $errors;
}
?>
Voorbeeld: Patch reversing example
The following code reverses a patch.
<?php
$new_version = 'my_script-1.1.php';
$patch = 'my_script.patch';
$errors = xdiff_file_patch($new_version, $patch, 'my_script-1.0.php', XDIFF_PATCH_REVERSE);
if (is_string($errors)) {
echo "Rejects:\n";
echo $errors;
}
?>
xdiff_file_diff