<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.mbstring.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.mb-ereg-replace-callback.php',
    1 => 'mb_ereg_replace_callback',
    2 => 'Rechercher et remplacer par expression r&eacute;guli&egrave;re avec support multi octets utilisant une fonction de callback',
  ),
  'up' => 
  array (
    0 => 'ref.mbstring.php',
    1 => 'Fonctions sur les cha&icirc;nes de caract&egrave;res multioctets',
  ),
  'prev' => 
  array (
    0 => 'function.mb-ereg-replace.php',
    1 => 'mb_ereg_replace',
  ),
  'next' => 
  array (
    0 => 'function.mb-ereg-search.php',
    1 => 'mb_ereg_search',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/mbstring/functions/mb-ereg-replace-callback.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mb-ereg-replace-callback" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mb_ereg_replace_callback</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.4.1, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mb_ereg_replace_callback</span> &mdash; <span class="dc-title">Rechercher et remplacer par expression régulière avec support multi octets utilisant une fonction de callback
  </span></p>

 </div>
   
 <div class="refsect1 description" id="refsect1-function.mb-ereg-replace-callback-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mb_ereg_replace_callback</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">$pattern</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> <code class="parameter">$callback</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">$string</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$options</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></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.singleton.php" class="type false">false</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span></span></div>

  <p class="para rdfs-comment">
   Recherche les <code class="parameter">string</code> qui correspondent au paramètre 
   <code class="parameter">pattern</code>, puis remplace les textes qui correspondent
   avec le retour de la fonction <code class="parameter">callback</code>.  
  </p>
  <p class="para">
    Le comportement de cette fonction est presque identique à <span class="function"><a href="function.mb-ereg-replace.php" class="function">mb_ereg_replace()</a></span>, 
    à part le fait que le paramètre
    <code class="parameter">replacement</code>, doit spécifier une fonction de retour  
    <code class="parameter">callback</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-ereg-replace-callback-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">pattern</code></dt>
     <dd>
      <p class="para">
       L&#039;expression régulière.
      </p>
      <p class="para">
       Les caractères multi octets peuvent être utilisés dans le <code class="parameter">pattern</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">callback</code></dt>
     <dd>
      <p class="para">
        Un callback qui sera appelé et lui sera passé un tableau d&#039;éléments correspondants 
        dans la chaîne de caractères <code class="parameter">string</code>. Le callback doit retourner
        la chaîne remplacée.
      </p>
      <p class="para">
        On aura souvent besoin de la fonction <code class="parameter">callback</code> 
        pour <span class="function"><strong>mb_ereg_replace_callback()</strong></span> juste une fois.
        Dans ce cas il est possible d&#039;utiliser les
        <a href="functions.anonymous.php" class="link">fonctions anonymes</a> pour 
        déclarer une fonction de rappel lors de l&#039;appel de la fonction
        <span class="function"><strong>mb_ereg_replace_callback()</strong></span>. En faisant cela de cette manière
        on a toutes les informations nécessaires à l&#039;appel de la fonction
        en un seul endroit, ce qui permet d&#039;éviter d&#039;encombrer l&#039;espace de noms
        des fonctions avec un callback de fonction qui n&#039;est pas utilisé ailleurs.
      </p>
     </dd>
    
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       La <span class="type"><a href="language.types.string.php" class="type string">string</a></span> qui doit être vérifiée.
      </p>
     </dd>
    
    
     <dt><code class="parameter">options</code></dt>
     <dd>
      <p class="para">
       L&#039;option de recherche. Pour plus d&#039;explications, consulter <span class="function"><a href="function.mb-regex-set-options.php" class="function">mb_regex_set_options()</a></span>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.mb-ereg-replace-callback-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne un <span class="type"><a href="language.types.string.php" class="type string">string</a></span> en cas de succès, ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> en cas d&#039;erreur.
   Si <code class="parameter">string</code> n&#039;est pas valide pour l&#039;encodage courant,
   <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> est retourné.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mb-ereg-replace-callback-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>8.0.0</td>
       <td>
        <code class="parameter">options</code> est désormais nullable.
       </td>
      </tr>

      <tr>
       <td>7.1.0</td>
       <td>
        Cette fonction vérifie si <code class="parameter">string</code> est valide pour
        l&#039;encodage courant.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mb-ereg-replace-callback-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>mb_ereg_replace_callback()</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 /></span><span style="color: #FF8000">// this text was used in 2002<br />// we want to get this up to date for 2003<br /></span><span style="color: #0000BB">$text </span><span style="color: #007700">= </span><span style="color: #DD0000">"April fools day is 04/01/2002\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$text</span><span style="color: #007700">.= </span><span style="color: #DD0000">"Last christmas was 12/24/2001\n"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// the callback function<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">next_year</span><span style="color: #007700">(</span><span style="color: #0000BB">$matches</span><span style="color: #007700">)<br />{<br />  </span><span style="color: #FF8000">// as usual: $matches[0] is the complete match<br />  // $matches[1] the match for the first subpattern<br />  // enclosed in '(...)' and so on<br />  </span><span style="color: #007700">return </span><span style="color: #0000BB">$matches</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">].(</span><span style="color: #0000BB">$matches</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">]+</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />}<br />echo </span><span style="color: #0000BB">mb_ereg_replace_callback</span><span style="color: #007700">(<br />            </span><span style="color: #DD0000">"(\d{2}/\d{2}/)(\d{4})"</span><span style="color: #007700">,<br />            </span><span style="color: #DD0000">"next_year"</span><span style="color: #007700">,<br />            </span><span style="color: #0000BB">$text</span><span style="color: #007700">);<br /><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">April fools day is 04/01/2003
Last christmas was 12/24/2002</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Exemple #2 <span class="function"><strong>mb_ereg_replace_callback()</strong></span> utilisant les fonctions anonymes</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// this text was used in 2002<br />// we want to get this up to date for 2003<br /></span><span style="color: #0000BB">$text </span><span style="color: #007700">= </span><span style="color: #DD0000">"April fools day is 04/01/2002\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$text</span><span style="color: #007700">.= </span><span style="color: #DD0000">"Last christmas was 12/24/2001\n"</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #0000BB">mb_ereg_replace_callback</span><span style="color: #007700">(<br />            </span><span style="color: #DD0000">"(\d{2}/\d{2}/)(\d{4})"</span><span style="color: #007700">,<br />            function (</span><span style="color: #0000BB">$matches</span><span style="color: #007700">) {<br />               return </span><span style="color: #0000BB">$matches</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">].(</span><span style="color: #0000BB">$matches</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">]+</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />            },<br />            </span><span style="color: #0000BB">$text</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 notes" id="refsect1-function.mb-ereg-replace-callback-notes">
  <h3 class="title">Notes</h3>

  <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">L&#039;encodage interne ou l&#039;encodage
    des caractères spécifié par la fonction <span class="function"><a href="function.mb-regex-encoding.php" class="function">mb_regex_encoding()</a></span> sera utilisé
    comme encodage de caractères pour cette fonction.</p></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mb-ereg-replace-callback-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.mb-regex-encoding.php" class="function" rel="rdfs-seeAlso">mb_regex_encoding()</a> - D&eacute;finit/R&eacute;cup&egrave;re l'encodage des caract&egrave;res pour les expressions r&eacute;guli&egrave;res multioctets</span></li>
    <li><span class="function"><a href="function.mb-ereg-replace.php" class="function" rel="rdfs-seeAlso">mb_ereg_replace()</a> - Remplace des segments de cha&icirc;ne &agrave; l'aide des expressions r&eacute;guli&egrave;res</span></li>
    <li><a href="functions.anonymous.php" class="link">Fonctions anonymes</a></li>
   </ul>
  </p>
 </div>


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