xdiff_string_patch
xdiff_string_patch
Patch a string with an unified diff
string **xdiff_string_patch** string $str string $patch int $flags string $error
Patches a string with an unified patch in parameter
and returns the result. has to be an unified diff created by
/ function.
An optional parameter specifies mode of operation. Any
rejected parts of the patch will be stored inside variable if
it is provided.
str``patch``patch``xdiff_file_diff``xdiff_string_diff``flags``error
strThe original string.
patch
The unified patch string. It has to be created using ,
functions or compatible tools.
xdiff_string_diff``xdiff_file_diff
flags
can be either
(default mode, normal patch)
or (reversed patch).
flags``XDIFF_PATCH_NORMAL``XDIFF_PATCH_REVERSE
Starting from version 1.5.0, you can also use binary OR to enable
flag.
`XDIFF_PATCH_IGNORESPACE`
errorIf provided then rejected parts are stored inside this variable.
Returns the patched string, or false on error.
Voorbeeld: example
The following code applies changes to some article.
<?php
$old_article = file_get_contents('./old_article.txt');
$diff = $_SERVER['patch']; /* Let's say that someone pasted a patch to html form */
$errors = '';
$new_article = xdiff_string_patch($old_article, $diff, XDIFF_PATCH_NORMAL, $errors);
if (is_string($new_article)) {
echo "New article:\n";
echo $new_article;
}
if (strlen($errors)) {
echo "Rejects: \n";
echo $errors;
}
?>
xdiff_string_diff