function.xdiff-file-patch.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 174 行

HTML
174
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Patch a file with an unified diff</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.xdiff-file-patch-binary.html">xdiff_file_patch_binary</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.xdiff-file-rabdiff.html">xdiff_file_rabdiff</a></div> <div class="up"><a href="ref.xdiff.html">xdiff Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.xdiff-file-patch" class="refentry"> <div class="refnamediv">  <h1 class="refname">xdiff_file_patch</h1>  <p class="verinfo">(PECL xdiff:0.2-1.4)</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">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b><b>xdiff_file_patch</b></b></span>    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$file</tt></span>   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$patch</tt></span>   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$dest</tt></span>   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$flags</tt></span>  ] )</div>  <p class="para rdfs-comment">   Patches a <i><tt class="parameter">file</tt></i> with a <i><tt class="parameter">patch</tt></i> and stores the result in a file.   <i><tt class="parameter">patch</tt></i> has to be an unified diff created by    <a href="function.xdiff-file-diff.html" class="function">xdiff_file_diff()</a>/<a href="function.xdiff-string-diff.html" class="function">xdiff_string_diff()</a> function.    An optional <i><tt class="parameter">flags</tt></i> parameter specifies mode of operation.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">file</tt></i></span>     <dd>      <p class="para">       The original file.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">patch</tt></i></span>     <dd>      <p class="para">       The unified patch file. It has to be created using <a href="function.xdiff-string-diff.html" class="function">xdiff_string_diff()</a>,        <a href="function.xdiff-file-diff.html" class="function">xdiff_file_diff()</a> functions or compatible tools.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">dest</tt></i></span>     <dd>      <p class="para">       Path of the resulting file.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">flags</tt></i></span>     <dd>      <p class="para">       Can be either <b><tt>XDIFF_PATCH_NORMAL</tt></b> (default mode,       normal patch) or <b><tt>XDIFF_PATCH_REVERSE</tt></b> (reversed       patch).      </p>      <p class="para">       Starting from version 1.5.0, you can also use binary OR to enable       <b><tt>XDIFF_PATCH_IGNORESPACE</tt></b> flag.      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   Returns <b><tt>FALSE</tt></b> if an internal error happened, string with rejected   chunks if patch couldn&#039;t be applied or <b><tt>TRUE</tt></b> if patch has been successfully applied.  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>xdiff_file_patch()</b> example</b></p>    <div class="example-contents"><p>     The following code applies unified diff to a file.    </p></div>    <div class="example-contents"><div class="phpcode"><code><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></code></div>    </div>   </div>   <div class="example">    <p><b>Example #2 Patch reversing example</b></p>    <div class="example-contents"><p>     The following code reverses a patch.    </p></div>    <div class="example-contents"><div class="phpcode"><code><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></code></div>    </div>   </div>  </p> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.xdiff-file-diff.html" class="function" rel="rdfs-seeAlso">xdiff_file_diff()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.xdiff-file-patch-binary.html">xdiff_file_patch_binary</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.xdiff-file-rabdiff.html">xdiff_file_rabdiff</a></div> <div class="up"><a href="ref.xdiff.html">xdiff Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?