xdiff_string_patch
(PECL)
xdiff_string_patch -- Patche une chaîne avec un diff unifié
Description
string
xdiff_string_patch ( string str, string patch [, int flags [, string &error]] )
xdiff_string_patch() patche la chaîne
str avec le patch unifié contenu dans la chaîne
patch.
flags peut être soit
XDIFF_PATCH_NORMAL (mode par défaut, patch normal),
soit XDIFF_PATCH_REVERSE (patch inversé).
Si error est fourni, les parties rejetées y sont
stockées.
Exemple 1. Exemple avec xdiff_string_patch()
Le code suivant applique les changements à des articles.
|
<?php
$ancien_article = file_get_contents('./ancien_article.txt');
$diff = $_SERVER['patch']; $errors = '';
$nouvel_article = xdiff_string_patch($ancien_article, $diff, XDIFF_PATCH_NORMAL, $errors);
if (is_string($nouvel_article)) {
echo "Nouvel article:\n";
echo $nouvel_article;
}
if (strlen($errors)) {
echo "Rejets : \n";
echo $errors;
}
?>
|
|
Retourne une chaîne patchée.
Voir aussi xdiff_file_patch().