Most Referenced Functions
  » google_pagerank()
  » preg_replace()
  » imagecreatefrompng()
  » site_pageranks()
  » imagepng()
  » imagedestroy()
  » imagestring()
  » imagecolorallocate()
  » htmlentities()
  » preg_match()
  » fopen()
  » header()
  » getimagesize()
  » preg_match_all()
  » session_start()
  » htmlspecialchars()
  » ob_start()
  » ob_flush()
  » strstr()
  » flush()
  » strpos()
  » setcookie()
  » str_replace()
  » array2vars()
  » nl2br()
  » preg_split()
  » ereg()
  » ereg_replace()
  » urlencode()
  » readgzfile()

Become a sponsor for $15/month. Link is sitewide - PR5 homepage, 20+ PR4 pages, 90+ PR3 pages. Email dave[AT]icemelon[D0T]c0m.

PHP Functions

Function: xdiff_string_patch

(PECL)

xdiff_string_patch --  Patch a string with an unified diff

Description

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

xdiff_string_patch() patches string str with unified patch in string patch .

flags can be either XDIFF_PATCH_NORMAL (default mode, normal patch) or XDIFF_PATCH_REVERSE (reversed patch).

If error is passed then rejected parts are stored inside this variable.

Example 1. xdiff_string_patch() 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;
}

?>

Returns a patched string.

Related Function(s)

  • xdiff_file_patch()
  • xml_parser_create()
  • xml_parser_set_option()
  • xml_parser_create_ns()
  • xml_set_element_handler()
  • xml_set_character_data_handler()
  • xml_set_processing_instruction_handler()
  • xml_set_default_handler()
  • xml_set_unparsed_entity_decl_handler()
  • xml_set_notation_decl_handler()
  • xml_set_external_entity_ref_handler()
  • xml_parser_get_option()
  • xml_parse()
  • utf8_decode()
  • utf8_encode()
  • xml_error_string()
  • xml_get_current_byte_index()
  • xml_get_current_column_number()
  • xml_get_current_line_number()
  • xml_get_error_code()
  • xml_parse_into_struct()
  • xml_parser_free()
  • xml_set_end_namespace_decl_handler()
  • xml_set_object()
  • xml_set_start_namespace_decl_handler()
  • Icemelon -- PHP, CSS, Javascript Tutorials, & More!
      © 2005-2010 Icemelon.com   Email: dave[AT]icemelon[D0T]c0m