uTools-Manuals/docs/php/xdiff_file_patch.html
2019-04-08 23:22:26 +08:00

152 lines
7.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Patch a file with an unified diff</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.xdiff-file-patch" class="refentry">
<div class="refnamediv">
<h1 class="refname">xdiff_file_patch</h1>
<p class="verinfo">(PECL xdiff &gt;= 0.2.0)</p><p class="refpurpose"><span class="refname">xdiff_file_patch</span> &mdash; <span class="dc-title">Patch a file with an unified diff</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.xdiff-file-patch-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>xdiff_file_patch</strong></span>
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$file</code></span>
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$patch</code></span>
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$dest</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = DIFF_PATCH_NORMAL</span></span>
] ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>
<p class="para rdfs-comment">
Patches a <code class="parameter">file</code> with a <code class="parameter">patch</code> and stores the result in a file.
<code class="parameter">patch</code> has to be an unified diff created by
<span class="function"><a href="xdiff_file_diff.html" class="function">xdiff_file_diff()</a></span>/<span class="function"><a href="xdiff_string_diff.html" class="function">xdiff_string_diff()</a></span> function.
An optional <code class="parameter">flags</code> parameter specifies mode of operation.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.xdiff-file-patch-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">file</code></dt>
<dd>
<p class="para">
The original file.
</p>
</dd>
<dt>
<code class="parameter">patch</code></dt>
<dd>
<p class="para">
The unified patch file. It has to be created using <span class="function"><a href="xdiff_string_diff.html" class="function">xdiff_string_diff()</a></span>,
<span class="function"><a href="xdiff_file_diff.html" class="function">xdiff_file_diff()</a></span> functions or compatible tools.
</p>
</dd>
<dt>
<code class="parameter">dest</code></dt>
<dd>
<p class="para">
Path of the resulting file.
</p>
</dd>
<dt>
<code class="parameter">flags</code></dt>
<dd>
<p class="para">
Can be either <strong><code>XDIFF_PATCH_NORMAL</code></strong> (default mode,
normal patch) or <strong><code>XDIFF_PATCH_REVERSE</code></strong> (reversed
patch).
</p>
<p class="para">
Starting from version 1.5.0, you can also use binary OR to enable
<strong><code>XDIFF_PATCH_IGNORESPACE</code></strong> flag.
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.xdiff-file-patch-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
Returns <strong><code>FALSE</code></strong> if an internal error happened, string with rejected
chunks if patch couldn&#039;t be applied or <strong><code>TRUE</code></strong> if patch has been successfully applied.
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.xdiff-file-patch-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="setthreadtitle.example.basic">
<p><strong>Example #1 <span class="function"><strong>xdiff_file_patch()</strong></span> example</strong></p>
<div class="example-contents"><p>
The following code applies unified diff to a file.
</p></div>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$old_version&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'my_script-1.0.php'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$patch&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'my_script.patch'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$errors&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">xdiff_file_patch</span><span style="color: #007700">(</span><span style="color: #0000BB">$old_version</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$patch</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'my_script-1.1.php'</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">is_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$errors</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Rejects:\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$errors</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
<div class="example" id="example-2870">
<p><strong>Example #2 Patch reversing example</strong></p>
<div class="example-contents"><p>
The following code reverses a patch.
</p></div>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$new_version&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'my_script-1.1.php'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$patch&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'my_script.patch'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$errors&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">xdiff_file_patch</span><span style="color: #007700">(</span><span style="color: #0000BB">$new_version</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$patch</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'my_script-1.0.php'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">XDIFF_PATCH_REVERSE</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">is_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$errors</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Rejects:\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$errors</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.xdiff-file-patch-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="xdiff_file_diff.html" class="function" rel="rdfs-seeAlso">xdiff_file_diff()</a> - Make unified diff of two files</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>