downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.xdiff-file-patch.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.xdiff.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.xdiff-file-patch.php',
   
1 => 'xdiff_file_patch',
  ),
 
'up' =>
  array (
   
0 => 'ref.xdiff.php',
   
1 => 'xdiff Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.xdiff-file-patch-binary.php',
   
1 => 'xdiff_file_patch_binary',
  ),
 
'next' =>
  array (
   
0 => 'function.xdiff-file-rabdiff.php',
   
1 => 'xdiff_file_rabdiff',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<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>
 
 <a name="function.xdiff-file-patch.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.php#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b>xdiff_file_patch</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 class="initializer"> = DIFF_PATCH_NORMAL</span></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.php" class="function">xdiff_file_diff()</a>/<a href="function.xdiff-string-diff.php" class="function">xdiff_string_diff()</a> function.
   An optional <i><tt class="parameter">flags</tt></i>
 parameter specifies mode of operation.
  </p>
 </div>


 <a name="function.xdiff-file-patch.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">file</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       The original file.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">patch</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       The unified patch file. It has to be created using <a href="function.xdiff-string-diff.php" class="function">xdiff_string_diff()</a>,
       <a href="function.xdiff-file-diff.php" class="function">xdiff_file_diff()</a> functions or compatible tools.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">dest</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Path of the resulting file.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">flags</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Can be either <b><tt class="constant">XDIFF_PATCH_NORMAL</tt></b> (default mode,
       normal patch) or <b><tt class="constant">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 class="constant">XDIFF_PATCH_IGNORESPACE</tt></b> flag.
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="function.xdiff-file-patch.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <b><tt class="constant">FALSE</tt></b> if an internal error happened, string with rejected
   chunks if patch couldn&#039;t be applied or <b><tt class="constant">TRUE</tt></b> if patch has been successfully applied.
  </p>
 </div>


 <a name="function.xdiff-file-patch.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 <b>xdiff_file_patch()</b> example</b></p>
    <div class="example-contents para"><p>
     The following code applies unified diff to a file.
    </p></div>
    <div class="example-contents programlisting">
<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><p>
   </p><div class="example">
    <p><b>Example #2 Patch reversing example</b></p>
    <div class="example-contents para"><p>
     The following code reverses a patch.
    </p></div>
    <div class="example-contents programlisting">
<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>
  </p>
 </div>


 <a name="function.xdiff-file-patch.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.xdiff-file-diff.php" class="function" rel="rdfs-seeAlso">xdiff_file_diff()</a> - Make unified diff of two files</li>
   </ul><p>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites