Forum und email

xdiff_string_patch

(PECL xdiff:0.2-1.4)

xdiff_string_patch — Patche une chaîne avec un diff unifié

Description

string xdiff_string_patch ( string $str , string $patch [, int $flags [, string &$error ]] )

Patche la chaîne str avec le patch unifié contenu dans la chaîne patch .

Liste de paramètres

str

La chaîne originale.

patch

Le patch unifié.

flags

flags peut être soit XDIFF_PATCH_NORMAL (mode par défaut, patch normal), soit XDIFF_PATCH_REVERSE (patch inversé).

error

Si error est fourni, les parties rejetées y seront stockées.

Valeurs de retour

Retourne la chaîne patchée, ou FALSE si une erreur survient.

Exemples

Example#1 Exemple avec xdiff_string_patch()

Le code suivant applique les changements à des articles.

<?php
$old_article 
file_get_contents('./old_article.txt');
$diff $_SERVER['patch']; /* disons que quelqu'un a passé un patch via un formulaire html */

$errors '';

$new_article xdiff_string_patch($old_article$diffXDIFF_PATCH_NORMAL$errors);
if (
is_string($new_article)) {
    echo 
"Nouvel article :\n";
    echo 
$new_article;
}

if (
strlen($errors)) {
    echo 
"Rejets : \n";
    echo 
$errors;
}

?>

Voir aussi