<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.pcre.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.preg-replace-callback-array.php',
    1 => 'preg_replace_callback_array',
    2 => 'Effectue une recherche de correspondance avec une expression r&eacute;guli&egrave;re et remplace gr&acirc;ce &agrave; une fonction de rappel',
  ),
  'up' => 
  array (
    0 => 'ref.pcre.php',
    1 => 'Fonctions PCRE',
  ),
  'prev' => 
  array (
    0 => 'function.preg-replace-callback.php',
    1 => 'preg_replace_callback',
  ),
  'next' => 
  array (
    0 => 'function.preg-split.php',
    1 => 'preg_split',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/pcre/functions/preg-replace-callback-array.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.preg-replace-callback-array" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">preg_replace_callback_array</h1>
  <p class="verinfo">(PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">preg_replace_callback_array</span> &mdash; <span class="dc-title">Effectue une recherche de correspondance avec une expression régulière et remplace grâce à une fonction de rappel</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.preg-replace-callback-array-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>preg_replace_callback_array</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$pattern</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter">$subject</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">$limit</code><span class="initializer"> = -1</span></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 reference">&$count</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></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"> = 0</span></span><br>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span></span></div>

  <p class="para rdfs-comment">
   Le comportement de cette fonction est similaire à
   <span class="function"><a href="function.preg-replace-callback.php" class="function">preg_replace_callback()</a></span>, à l&#039;exception que les fonctions de rappel
   sont exécutées à chaque masque.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.preg-replace-callback-array-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">pattern</code></dt>
     <dd>
      <p class="para">
       Un tableau associatif qui établit une relation entre les masques (clés) 
       et les fonctions de rappels <span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> (valeurs).
      </p>
     </dd>
    
    
     <dt><code class="parameter">subject</code></dt>
     <dd>
      <p class="para">
       La <a href="language.types.string.php" class="link">chaîne de caractères</a> ou <a href="language.types.array.php" class="link">tableau</a> qui contient les <a href="language.types.string.php" class="link">chaîne de caractères</a> à chercher et remplacer.
      </p>
     </dd>
    
    
     <dt><code class="parameter">limit</code></dt>
     <dd>
      <p class="para">
       Le nombre maximum de remplacement pour chaque masque dans chaque
       <a href="language.types.string.php" class="link">chaîne de caractères</a> <code class="parameter">subject</code>. Par défaut
       <code class="literal">-1</code> (aucune limite).
      </p>
     </dd>
    
    
     <dt><code class="parameter">count</code></dt>
     <dd>
      <p class="para">
       Si fourni, cette variable sera remplie avec le nombre de
       remplacement effectué.
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">flags</code> peut être une combinaison des drapeaux
       <strong><code><a href="pcre.constants.php#constant.preg-offset-capture">PREG_OFFSET_CAPTURE</a></code></strong> et
       <strong><code><a href="pcre.constants.php#constant.preg-unmatched-as-null">PREG_UNMATCHED_AS_NULL</a></code></strong>, qui influence le format
       du tableau de correspondances.
       Voir la description de <span class="function"><a href="function.preg-match.php" class="function">preg_match()</a></span> pour plus de détail.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.preg-replace-callback-array-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   <span class="function"><strong>preg_replace_callback_array()</strong></span> retourne un tableau si
   le paramètre <code class="parameter">subject</code> est un tableau, ou sinon
   une <a href="language.types.string.php" class="link">chaîne de caractères</a>. Lors d&#039;une erreur la valeur de retour est <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
  </p>
  <p class="para">
   Si des correspondances sont trouvées, le nouveau sujet sera retourné, sinon
   <code class="parameter">subject</code> sera retourné inchangé.</p>
 </div>

 
 <div class="refsect1 errors" id="refsect1-function.preg-replace-callback-array-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <p class="para">
Si le masque regex passé ne compile pas à une regex valide, une <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> est émise.
</p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.preg-replace-callback-array-changelog">
  <h3 class="title">Historique</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.4.0</td>
       <td>
        Le paramètre <code class="parameter">flags</code> a été ajouté.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-function.preg-replace-callback-array-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple de <span class="function"><strong>preg_replace_callback_array()</strong></span></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$subject </span><span style="color: #007700">= </span><span style="color: #DD0000">'Aaaaaa Bbb'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">preg_replace_callback_array</span><span style="color: #007700">(<br />    [<br />        </span><span style="color: #DD0000">'~[a]+~i' </span><span style="color: #007700">=&gt; function (</span><span style="color: #0000BB">$match</span><span style="color: #007700">) {<br />            echo </span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$match</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]), </span><span style="color: #DD0000">' correspondances de "a" trouvées'</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />        },<br />        </span><span style="color: #DD0000">'~[b]+~i' </span><span style="color: #007700">=&gt; function (</span><span style="color: #0000BB">$match</span><span style="color: #007700">) {<br />            echo </span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$match</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]), </span><span style="color: #DD0000">' correspondances de "b" trouvées'</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />        }<br />    ],<br />    </span><span style="color: #0000BB">$subject<br /></span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">6 correspondances de &quot;a&quot; trouvées
3 correspondances de &quot;b&quot; trouvées</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.preg-replace-callback-array-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><a href="pcre.pattern.php" class="link">Masques PCRE</a></li>
    <li><span class="function"><a href="function.preg-replace-callback.php" class="function" rel="rdfs-seeAlso">preg_replace_callback()</a> - Rechercher et remplacer par expression rationnelle standard en utilisant une fonction de callback</span></li>
    <li><span class="function"><a href="function.preg-quote.php" class="function" rel="rdfs-seeAlso">preg_quote()</a> - Protection des caract&egrave;res sp&eacute;ciaux des expressions r&eacute;guli&egrave;res</span></li>
    <li><span class="function"><a href="function.preg-replace.php" class="function" rel="rdfs-seeAlso">preg_replace()</a> - Rechercher et remplacer par expression rationnelle standard</span></li>
    <li><span class="function"><a href="function.preg-last-error.php" class="function" rel="rdfs-seeAlso">preg_last_error()</a> - Retourne le code erreur de la derni&egrave;re expression PCRE ex&eacute;cut&eacute;e</span></li>
    <li><a href="functions.anonymous.php" class="link">Anonymous functions</a></li>
   </ul>
  </p>
 </div>


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