xdiff_file_bdiff_size

Read a size of file created by applying a binary diff

说明

int xdiff_file_bdiff_size ( string $file )

Returns a size of a result file that would be created after applying binary patch from file file to the original file.

参数

file
The path to the binary patch created by xdiff_string_bdiff or xdiff_string_rabdiff function.

返回值

Returns the size of file that would be created.

范例

示例 #1 xdiff_file_bdiff_size example

The following code applies reads a size of file that would be created after applying a binary diff.

<?php
$length = xdiff_string_bdiff_size('file.bdiff');
echo "Resulting file will be $length bytes long";
?>

参见

  • xdiff_file_bdiff
  • xdiff_file_rabdiff
  • xdiff_file_bpatch

xdiff_file_bdiff

Make binary diff of two files

说明

bool xdiff_file_bdiff ( string $old_file , string $new_file , string $dest )

Makes a binary diff of two files and stores the result in a patch file. This function works with both text and binary files. Resulting patch file can be later applied using xdiff_file_bpatch/xdiff_string_bpatch.

参数

old_file
Path to the first file. This file acts as "old" file.

new_file
Path to the second file. This file acts as "new" file.

dest
Path of the resulting patch file. Resulting file contains differences between "old" and "new" files. It is in binary format and is human-unreadable.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 xdiff_file_bdiff example

The following code makes binary diff of two archives.

<?php
$old_version = 'my_script_1.0.tgz';
$new_version = 'my_script_1.1.tgz';

xdiff_file_bdiff($old_version, $new_version, 'my_script.bdiff');
?>

注释

Note:

Both files will be loaded into memory so ensure that your memory_limit is set high enough.

参见

  • xdiff_file_bpatch

xdiff_file_bpatch

Patch a file with a binary diff

说明

bool xdiff_file_bpatch ( string $file , string $patch , string $dest )

Patches a file with a binary patch and stores the result in a file dest. This function accepts patches created both via xdiff_file_bdiff and xdiff_file_rabdiff functions or their string counterparts.

参数

file
The original file.

patch
The binary patch file.

dest
Path of the resulting file.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 xdiff_file_bpatch example

The following code applies binary diff to a file.

<?php
$old_version = 'archive-1.0.tgz';
$patch = 'archive.bpatch';

$result = xdiff_file_bpatch($old_version, $patch, 'archive-1.1.tgz');
if ($result) {
   echo "File patched";
} else {
   echo "File couldn't be patched";
}

?>

注释

Note:

Both files (file and patch) will be loaded into memory so ensure that your memory_limit is set high enough.

参见

  • xdiff_file_bdiff
  • xdiff_file_rabdiff

xdiff_file_diff_binary

Alias of xdiff_file_bdiff

说明

bool xdiff_file_diff_binary ( string $old_file , string $new_file , string $dest )

Makes a binary diff of two files and stores the result in a patch file. This function works with both text and binary files. Resulting patch file can be later applied using xdiff_file_bpatch.

Starting with version 1.5.0 this function is an alias of xdiff_file_bdiff.

参数

old_file
Path to the first file. This file acts as "old" file.

new_file
Path to the second file. This file acts as "new" file.

dest
Path of the resulting patch file. Resulting file contains differences between "old" and "new" files. It is in binary format and is human-unreadable.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 xdiff_file_diff_binary example

The following code makes binary diff of two archives.

<?php
$old_version = 'my_script_1.0.tgz';
$new_version = 'my_script_1.1.tgz';

xdiff_file_diff_binary($old_version, $new_version, 'my_script.bdiff');
?>

注释

Note:

Both files will be loaded into memory so ensure that your memory_limit is set high enough.

参见

  • xdiff_file_bdiff
  • xdiff_file_bpatch

xdiff_file_diff

Make unified diff of two files

说明

bool xdiff_file_diff ( string $old_file , string $new_file , string $dest [, int $context = 3 [, bool $minimal = FALSE ]] )

Makes an unified diff containing differences between old_file and new_file and stores it in dest file. The resulting file is human-readable. An optional context parameter specifies how many lines of context should be added around each change. Setting minimal parameter to true will result in outputting the shortest patch file possible (can take a long time).

参数

old_file
Path to the first file. This file acts as "old" file.

new_file
Path to the second file. This file acts as "new" file.

dest
Path of the resulting patch file.

context
Indicates how many lines of context you want to include in diff result.

minimal
Set this parameter to TRUE if you want to minimalize size of the result (can take a long time).

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 xdiff_file_diff example

The following code makes unified diff of two php files with context length of 2.

<?php
$old_version = 'my_script.php';
$new_version = 'my_new_script.php';

xdiff_file_diff($old_version, $new_version, 'my_script.diff', 2);
?>

注释

Note:

This function doesn't work well with binary files. To make diff of binary files use class="function">xdiff_file_bdiff/class="function">xdiff_file_rabdiff function.

参见

  • xdiff_file_patch

xdiff_file_merge3

Merge 3 files into one

说明

mixed xdiff_file_merge3 ( string $old_file , string $new_file1 , string $new_file2 , string $dest )

Merges three files into one and stores the result in a file dest. The old_file is an original version while new_file1 and new_file2 are modified versions of an original.

参数

old_file
Path to the first file. It acts as "old" file.

new_file1
Path to the second file. It acts as modified version of old_file.

new_file2
Path to the third file. It acts as modified version of old_file.

dest
Path of the resulting file, containing merged changed from both new_file1 and new_file2.

返回值

Returns TRUE if merge was successful, string with rejected chunks if it was not or FALSE if an internal error happened.

范例

示例 #1 xdiff_file_merge3 example

The following code merges three files into one.

<?php
$old_version = 'original_script.php';
$fix1 = 'script_with_fix1.php';
$fix2 = 'script_with_fix2.php';

$errors = xdiff_file_merge3($old_version, $fix1, $fix2, 'fixed_script.php');
if (is_string($errors)) {
    echo "Rejects:\n";
    echo $errors;
}
?>

参见

  • xdiff_string_merge3

xdiff_file_patch_binary

Alias of xdiff_file_bpatch

说明

bool xdiff_file_patch_binary ( string $file , string $patch , string $dest )

Patches a file with a binary patch and stores the result in a file dest. This function accepts patches created both via xdiff_file_bdiff or xdiff_file_rabdiff functions or their string counterparts.

Starting with version 1.5.0 this function is an alias of xdiff_file_bpatch.

参数

file
The original file.

patch
The binary patch file.

dest
Path of the resulting file.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 xdiff_file_patch_binary example

The following code applies binary diff to a file.

<?php
$old_version = 'archive-1.0.tgz';
$patch = 'archive.bpatch';

$result = xdiff_file_patch_binary($old_version, $patch, 'archive-1.1.tgz');
if ($result) {
   echo "File patched";
} else {
   echo "File couldn't be patched";
}

?>

注释

Note:

Both files (file and patch) will be loaded into memory so ensure that your memory_limit is set high enough.

参见

  • xdiff_string_patch_binary

xdiff_file_patch

Patch a file with an unified diff

说明

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

Patches a file with a patch and stores the result in a file. patch has to be an unified diff created by xdiff_file_diff/xdiff_string_diff function. An optional flags parameter specifies mode of operation.

参数

file
The original file.

patch
The unified patch file. It has to be created using xdiff_string_diff, xdiff_file_diff functions or compatible tools.

dest
Path of the resulting file.

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

Starting from version 1.5.0, you can also use binary OR to enable XDIFF_PATCH_IGNORESPACE flag.

返回值

Returns FALSE if an internal error happened, string with rejected chunks if patch couldn't be applied or TRUE if patch has been successfully applied.

范例

示例 #1 xdiff_file_patch example

The following code applies unified diff to a file.

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

?>

示例 #2 Patch reversing example

The following code reverses a patch.

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

?>

参见

  • xdiff_file_diff

xdiff_file_rabdiff

Make binary diff of two files using the Rabin's polynomial fingerprinting algorithm

说明

bool xdiff_file_rabdiff ( string $old_file , string $new_file , string $dest )

Makes a binary diff of two files and stores the result in a patch file. The difference between this function and xdiff_file_bdiff is different algorithm used which should result in faster execution and smaller diff produced. This function works with both text and binary files. Resulting patch file can be later applied using xdiff_file_bpatch/xdiff_string_bpatch.

For more details about differences between algorithm used please check » libxdiff website.

参数

old_file
Path to the first file. This file acts as "old" file.

new_file
Path to the second file. This file acts as "new" file.

dest
Path of the resulting patch file. Resulting file contains differences between "old" and "new" files. It is in binary format and is human-unreadable.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 xdiff_file_rabdiff example

The following code makes binary diff of two archives.

<?php
$old_version = 'my_script_1.0.tgz';
$new_version = 'my_script_1.1.tgz';

xdiff_file_rabdiff($old_version, $new_version, 'my_script.bdiff');
?>

注释

Note:

Both files will be loaded into memory so ensure that your memory_limit is set high enough.

参见

  • xdiff_file_bpatch

xdiff_string_bdiff_size

Read a size of file created by applying a binary diff

说明

int xdiff_string_bdiff_size ( string $patch )

Returns a size of a result file that would be created after applying binary patch to the original file.

参数

patch
The binary patch created by xdiff_string_bdiff or xdiff_string_rabdiff function.

返回值

Returns the size of file that would be created.

范例

示例 #1 xdiff_string_bdiff_size example

The following code applies reads a size of file that would be created after applying a binary diff.

<?php
$binary_patch = file_get_contents('file.bdiff');
$length = xdiff_string_bdiff_size($binary_patch);
echo "Resulting file will be $length bytes long";
?>

参见

  • xdiff_string_bdiff
  • xdiff_string_rabdiff
  • xdiff_string_bpatch

xdiff_string_bdiff

Make binary diff of two strings

说明

string xdiff_string_bdiff ( string $old_data , string $new_data )

Makes a binary diff of two strings and returns the result. This function works with both text and binary data. Resulting patch can be later applied using xdiff_string_bpatch/xdiff_file_bpatch.

参数

old_data
First string with binary data. It acts as "old" data.

new_data
Second string with binary data. It acts as "new" data.

返回值

Returns string with binary diff containing differences between "old" and "new" data or FALSE if an internal error occurred.

参见

  • xdiff_string_bpatch

xdiff_string_bpatch

Patch a string with a binary diff

说明

string xdiff_string_bpatch ( string $str , string $patch )

Patches a string str with a binary patch. This function accepts patches created both via xdiff_string_bdiff and xdiff_string_rabdiff functions or their file counterparts.

参数

str
The original binary string.

patch
The binary patch string.

返回值

Returns the patched string, or FALSE on error.

参见

  • xdiff_string_bdiff
  • xdiff_string_rabdiff

xdiff_string_diff_binary

Alias of xdiff_string_bdiff

说明

string xdiff_string_bdiff ( string $old_data , string $new_data )

Makes a binary diff of two strings and returns the result. This function works with both text and binary data. Resulting patch can be later applied using xdiff_string_bpatch/xdiff_file_bpatch.

Starting with version 1.5.0 this function is an alias of xdiff_string_bdiff.

参数

old_data
First string with binary data. It acts as "old" data.

new_data
Second string with binary data. It acts as "new" data.

返回值

Returns string with result or FALSE if an internal error happened.

参见

  • xdiff_string_bdiff
  • xdiff_string_bpatch

xdiff_string_diff

Make unified diff of two strings

说明

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

Makes an unified diff containing differences between old_data string and new_data string and returns it. The resulting diff is human-readable. An optional context parameter specifies how many lines of context should be added around each change. Setting minimal parameter to true will result in outputting the shortest patch file possible (can take a long time).

参数

old_data
First string with data. It acts as "old" data.

new_data
Second string with data. It acts as "new" data.

context
Indicates how many lines of context you want to include in the diff result.

minimal
Set this parameter to TRUE if you want to minimalize the size of the result (can take a long time).

返回值

Returns string with resulting diff or FALSE if an internal error happened.

范例

示例 #1 xdiff_string_diff example

The following code makes unified diff of two articles.

<?php
$old_article = file_get_contents('./old_article.txt');
$new_article = $_REQUEST['article']; /* Let's say that someone pasted a new article to html form */

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

?>

注释

Note:

This function doesn't work well with binary strings. To make diff of binary strings use class="function">xdiff_string_bdiff/class="function">xdiff_string_rabdiff.

参见

  • xdiff_string_patch

xdiff_string_merge3

Merge 3 strings into one

说明

mixed xdiff_string_merge3 ( string $old_data , string $new_data1 , string $new_data2 [, string &$error ] )

Merges three strings into one and returns the result. The old_data is an original version of data while new_data1 and new_data2 are modified versions of an original. An optional error is used to pass any rejected parts during merging process.

参数

old_data
First string with data. It acts as "old" data.

new_data1
Second string with data. It acts as modified version of old_data.

new_data2
Third string with data. It acts as modified version of old_data.

error
If provided then rejected parts are stored inside this variable.

返回值

Returns the merged string, FALSE if an internal error happened, or TRUE if merged string is empty.

参见

  • xdiff_file_merge3

xdiff_string_patch_binary

Alias of xdiff_string_bpatch

说明

string xdiff_string_patch_binary ( string $str , string $patch )

Patches a string str with a binary patch. This function accepts patches created both via xdiff_string_bdiff and xdiff_string_rabdiff functions or their file counterparts.

Starting with version 1.5.0 this function is an alias of xdiff_string_bpatch.

参数

str
The original binary string.

patch
The binary patch string.

返回值

Returns the patched string, or FALSE on error.

参见

  • xdiff_string_bpatch
  • xdiff_string_bdiff
  • xdiff_string_rabdiff

xdiff_string_patch

Patch a string with an unified diff

说明

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

Patches a str string with an unified patch in patch parameter and returns the result. patch has to be an unified diff created by xdiff_file_diff/xdiff_string_diff function. An optional flags parameter specifies mode of operation. Any rejected parts of the patch will be stored inside error variable if it is provided.

参数

str
The original string.

patch
The unified patch string. It has to be created using xdiff_string_diff, xdiff_file_diff functions or compatible tools.

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

Starting from version 1.5.0, you can also use binary OR to enable XDIFF_PATCH_IGNORESPACE flag.

error
If provided then rejected parts are stored inside this variable.

返回值

Returns the patched string, or FALSE on error.

范例

示例 #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;
}

?>

参见

  • xdiff_string_diff

xdiff_string_rabdiff

Make binary diff of two strings using the Rabin's polynomial fingerprinting algorithm

说明

string xdiff_string_bdiff ( string $old_data , string $new_data )

Makes a binary diff of two strings and returns the result. The difference between this function and xdiff_string_bdiff is different algorithm used which should result in faster execution and smaller diff produced. This function works with both text and binary data. Resulting patch can be later applied using xdiff_string_bpatch/xdiff_file_bpatch.

For more details about differences between algorithm used please check » libxdiff website.

参数

old_data
First string with binary data. It acts as "old" data.

new_data
Second string with binary data. It acts as "new" data.

返回值

Returns string with binary diff containing differences between "old" and "new" data or FALSE if an internal error occurred.

参见

  • xdiff_string_bpatch

目录