• PHP Video Tutorials

PHP - xdiff file_patch() Function



xdiff_file_patch() function can patch a file with an unified diff.

Syntax

mixed xdiff_file_patch( string $file , string $patch , string $dest [, int $flags = DIFF_PATCH_NORMAL ] )

xdiff_file_patch() function can patch a file with patch and store the result in a file. The patch has to be unified diff created by xdiff_file_diff()/xdiff_string_diff() function. An optional flag parameter can specify the mode of operation.

xdiff_file_patch() function can return false if an internal error occurred, string with rejected chunks if the patch can't be applied, or true if the patch has been successfully applied.

Example 1

<?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;
   }
?>

Example 2

<?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;
   }
?>
php_function_reference.htm
Advertisements