Ref/xdiff-Phpdoc专题
xdiff_file_bdiff_size
Read a size of file created by applying a binary diff
说明
int <span
class="methodname">xdiff_file_bdiff_size ( <span
class="methodparam">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 <span
class="function">xdiff_string_bdiff or <span
class="function">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 <span
class="methodname">xdiff_file_bdiff ( <span
class="methodparam">string $old_file
, string
$new_file , <span
class="type">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 <span class="function">xdiff_file_bpatch/<span class="function">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 <span
class="methodname">xdiff_file_bpatch ( <span
class="methodparam">string $file ,
string
$patch , <span
class="type">string $dest )
Patches a file with a binary patch and stores the result in a file
dest. This function accepts patches created both via <span
class="function">xdiff_file_bdiff and <span
class="function">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 (
fileandpatch) 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 <span
class="methodname">xdiff_file_diff_binary ( <span
class="methodparam">string $old_file
, string
$new_file , <span
class="type">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 <span class="function">xdiff_file_bpatch.
Starting with version 1.5.0 this function is an alias of <span class="function">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 <span
class="methodname">xdiff_file_diff ( <span
class="methodparam">string $old_file
, string
$new_file , <span
class="type">string $dest [, <span
class="methodparam">int $context<span
class="initializer"> = 3 [, <span
class="methodparam">bool $minimal<span
class="initializer"> = 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 <span class="function">xdiff_file_bdiff/<span class="function">xdiff_file_rabdiff function.
参见
- xdiff_file_patch
xdiff_file_merge3
Merge 3 files into one
说明
mixed <span
class="methodname">xdiff_file_merge3 ( <span
class="methodparam">string $old_file
, string
$new_file1 , <span
class="type">string $new_file2 , <span
class="methodparam">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 <span
class="methodname">xdiff_file_patch_binary ( <span
class="methodparam">string $file ,
string
$patch , <span
class="type">string $dest )
Patches a file with a binary patch and stores the result in a file
dest. This function accepts patches created both via <span
class="function">xdiff_file_bdiff or <span
class="function">xdiff_file_rabdiff functions or their string
counterparts.
Starting with version 1.5.0 this function is an alias of <span class="function">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 (
fileandpatch) 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 <span
class="methodname">xdiff_file_patch ( <span
class="methodparam">string $file ,
string
$patch , <span
class="type">string $dest [, <span
class="methodparam">int $flags<span
class="initializer"> = 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 <span
class="function">xdiff_file_diff/<span
class="function">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 <span
class="function">xdiff_string_diff, <span
class="function">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 <span
class="methodname">xdiff_file_rabdiff ( <span
class="methodparam">string $old_file
, string
$new_file , <span
class="type">string $dest )
Makes a binary diff of two files and stores the result in a patch file. The difference between this function and <span class="function">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 <span class="function">xdiff_file_bpatch/<span class="function">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 <span
class="methodname">xdiff_string_bdiff_size ( <span
class="methodparam">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 <span
class="function">xdiff_string_bdiff or <span
class="function">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 <span
class="methodname">xdiff_string_bdiff ( <span
class="methodparam">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/<span class="function">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 <span
class="methodname">xdiff_string_bpatch ( <span
class="methodparam">string $str ,
string
$patch )
Patches a string str with a binary patch. This function accepts
patches created both via <span
class="function">xdiff_string_bdiff and <span
class="function">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 <span
class="methodname">xdiff_string_bdiff ( <span
class="methodparam">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/<span class="function">xdiff_file_bpatch.
Starting with version 1.5.0 this function is an alias of <span class="function">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 <span
class="methodname">xdiff_string_diff ( <span
class="methodparam">string $old_data
, string
$new_data [, <span
class="type">int $context =
3 [, <span
class="type">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 <span class="function">xdiff_string_bdiff/<span class="function">xdiff_string_rabdiff.
参见
- xdiff_string_patch
xdiff_string_merge3
Merge 3 strings into one
说明
mixed <span
class="methodname">xdiff_string_merge3 ( <span
class="methodparam">string $old_data
, string
$new_data1 , <span
class="type">string $new_data2 [, <span
class="methodparam">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 <span
class="methodname">xdiff_string_patch_binary ( <span
class="methodparam">string $str ,
string
$patch )
Patches a string str with a binary patch. This function accepts
patches created both via <span
class="function">xdiff_string_bdiff and <span
class="function">xdiff_string_rabdiff functions or their file
counterparts.
Starting with version 1.5.0 this function is an alias of <span class="function">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 <span
class="methodname">xdiff_string_patch ( <span
class="methodparam">string $str ,
string
$patch [, <span
class="type">int $flags [, <span
class="methodparam">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 <span
class="function">xdiff_file_diff/<span
class="function">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 <span
class="function">xdiff_string_diff, <span
class="function">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 <span
class="methodname">xdiff_string_bdiff ( <span
class="methodparam">string $old_data
, string
$new_data )
Makes a binary diff of two strings and returns the result. The difference between this function and <span class="function">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 <span class="function">xdiff_string_bpatch/<span class="function">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
目录
- xdiff_file_bdiff_size — Read a size of file created by applying a binary diff
- xdiff_file_bdiff — Make binary diff of two files
- xdiff_file_bpatch — Patch a file with a binary diff
- xdiff_file_diff_binary — Alias of xdiff_file_bdiff
- xdiff_file_diff — Make unified diff of two files
- xdiff_file_merge3 — Merge 3 files into one
- xdiff_file_patch_binary — Alias of xdiff_file_bpatch
- xdiff_file_patch — Patch a file with an unified diff
- xdiff_file_rabdiff — Make binary diff of two files using the Rabin's polynomial fingerprinting algorithm
- xdiff_string_bdiff_size — Read a size of file created by applying a binary diff
- xdiff_string_bdiff — Make binary diff of two strings
- xdiff_string_bpatch — Patch a string with a binary diff
- xdiff_string_diff_binary — Alias of xdiff_string_bdiff
- xdiff_string_diff — Make unified diff of two strings
- xdiff_string_merge3 — Merge 3 strings into one
- xdiff_string_patch_binary — Alias of xdiff_string_bpatch
- xdiff_string_patch — Patch a string with an unified diff
- xdiff_string_rabdiff — Make binary diff of two strings using the Rabin's polynomial fingerprinting algorithm