• PHP Video Tutorials

PHP - xdiff string_diff() Function



xdiff_string_diff() function can make a unified diff of two strings.

Syntax

string xdiff_string_diff( string $old_data , string $new_data [, int $context = 3 [, bool $minimal = false ]] )

xdiff_string_diff() function can make a unified diff containing differences between old_data string and new_data string and return it. The resulting diff can be human-readable. An optional context parameter can specify how many lines of context has added around each change. Setting the minimal parameter to true can result in outputting the shortest patch file possible (can take a long time).

xdiff_string_diff() function can return a string with resulting diff or false if an internal error has occurred.

Example

<?php
   $old_article = file_get_contents("./old_article.txt");
   $new_article = $_REQUEST["article"];

   $diff = xdiff_string_diff($old_article, $new_article, 1);
   if(is_string($diff)) {
      echo "Differences between two articles:\n";
      echo $diff;
   }
?>
php_function_reference.htm
Advertisements