<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = 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 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.xdiff-file-patch.php',
    1 => 'xdiff_file_patch',
    2 => 'Patch a file with an unified diff',
  ),
  'up' => 
  array (
    0 => 'ref.xdiff.php',
    1 => 'xdiff Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.xdiff-file-merge3.php',
    1 => 'xdiff_file_merge3',
  ),
  'next' => 
  array (
    0 => 'function.xdiff-file-patch-binary.php',
    1 => 'xdiff_file_patch_binary',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/xdiff/functions/xdiff-file-patch.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<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">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>xdiff_file_patch</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$file</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$patch</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$dest</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = DIFF_PATCH_NORMAL</span></span><br>): <span class="type"><a href="language.types.mixed.php" 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="function.xdiff-file-diff.php" class="function">xdiff_file_diff()</a></span>/<span class="function"><a href="function.xdiff-string-diff.php" 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">Elenco dei parametri</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="function.xdiff-string-diff.php" class="function">xdiff_string_diff()</a></span>, 
       <span class="function"><a href="function.xdiff-file-diff.php" 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><a href="xdiff.constants.php#constant.xdiff-patch-normal">XDIFF_PATCH_NORMAL</a></code></strong> (default mode,
       normal patch) or <strong><code><a href="xdiff.constants.php#constant.xdiff-patch-reverse">XDIFF_PATCH_REVERSE</a></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">Valori restituiti</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if an internal error happened, string with rejected
   chunks if patch couldn&#039;t be applied or <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> if patch has been successfully applied.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.xdiff-file-patch-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <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"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$old_version </span><span style="color: #007700">= </span><span style="color: #DD0000">'my_script-1.0.php'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$patch </span><span style="color: #007700">= </span><span style="color: #DD0000">'my_script.patch'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$errors </span><span style="color: #007700">= </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">, </span><span style="color: #0000BB">$patch</span><span style="color: #007700">, </span><span style="color: #DD0000">'my_script-1.1.php'</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">is_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$errors</span><span style="color: #007700">)) {<br />   echo </span><span style="color: #DD0000">"Rejects:\n"</span><span style="color: #007700">;<br />   echo </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" id="example-2">
    <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"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$new_version </span><span style="color: #007700">= </span><span style="color: #DD0000">'my_script-1.1.php'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$patch </span><span style="color: #007700">= </span><span style="color: #DD0000">'my_script.patch'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$errors </span><span style="color: #007700">= </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">, </span><span style="color: #0000BB">$patch</span><span style="color: #007700">, </span><span style="color: #DD0000">'my_script-1.0.php'</span><span style="color: #007700">, </span><span style="color: #0000BB">XDIFF_PATCH_REVERSE</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">is_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$errors</span><span style="color: #007700">)) {<br />   echo </span><span style="color: #DD0000">"Rejects:\n"</span><span style="color: #007700">;<br />   echo </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" id="refsect1-function.xdiff-file-patch-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.xdiff-file-diff.php" class="function" rel="rdfs-seeAlso">xdiff_file_diff()</a> - Make unified diff of two files</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>