<?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 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.mb-ereg-replace-callback.php',
    1 => 'mb_ereg_replace_callback',
    2 => 'Perform a regular expression search and replace with multibyte support using a callback',
  ),
  'up' => 
  array (
    0 => 'ref.mbstring.php',
    1 => 'Multibyte String Funktionen',
  ),
  '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' => 'en',
    '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">Perform a regular expression search and replace with multibyte support using a callback
  </span></p>

 </div>
   
 <div class="refsect1 description" id="refsect1-function.mb-ereg-replace-callback-description">
  <h3 class="title">Beschreibung</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">
   Scans <code class="parameter">string</code> for matches to
   <code class="parameter">pattern</code>, then replaces the matched text
   with the output of <code class="parameter">callback</code> function.  
  </p>
  <p class="para">
    The behavior of this function is almost identical to <span class="function"><a href="function.mb-ereg-replace.php" class="function">mb_ereg_replace()</a></span>, 
    except for the fact that instead of
    <code class="parameter">replacement</code> parameter, one should specify a
    <code class="parameter">callback</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-ereg-replace-callback-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">pattern</code></dt>
     <dd>
      <p class="para">
       The regular expression pattern.
      </p>
      <p class="para">
       Multibyte characters may be used in <code class="parameter">pattern</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">callback</code></dt>
     <dd>
      <p class="para">
        A callback that will be called and passed an array of matched elements
        in the  <code class="parameter">string</code> string. The callback should
       return the replacement string.
      </p>
      <p class="para">
        You&#039;ll often need the <code class="parameter">callback</code> function
        for a <span class="function"><strong>mb_ereg_replace_callback()</strong></span> in just one place.
        In this case you can use an
        <a href="functions.anonymous.php" class="link">anonymous function</a> to
        declare the callback within the call to
        <span class="function"><strong>mb_ereg_replace_callback()</strong></span>. By doing it this way
        you have all information for the call in one place and do not
        clutter the function namespace with a callback function&#039;s name
        not used anywhere else.        
      </p>
     </dd>
    
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       The <span class="type"><a href="language.types.string.php" class="type string">string</a></span> being checked.
      </p>
     </dd>
    
    
     <dt><code class="parameter">options</code></dt>
     <dd>
      <p class="para">
       The search option. See <span class="function"><a href="function.mb-regex-set-options.php" class="function">mb_regex_set_options()</a></span> for explanation.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.mb-ereg-replace-callback-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   The resultant <span class="type"><a href="language.types.string.php" class="type string">string</a></span> on success, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on error.
   If <code class="parameter">string</code> is not valid for the current encoding, <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>
   is returned.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mb-ereg-replace-callback-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Beschreibung</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.0.0</td>
       <td>
        <code class="parameter">options</code> is nullable now.
       </td>
      </tr>

      <tr>
       <td>7.1.0</td>
       <td>
        The function checks whether <code class="parameter">string</code> is valid for the
        current encoding.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mb-ereg-replace-callback-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 <span class="function"><strong>mb_ereg_replace_callback()</strong></span> example</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>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</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>Beispiel #2 <span class="function"><strong>mb_ereg_replace_callback()</strong></span> using anonymous function</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">Anmerkungen</h3>

  <blockquote class="note"><p><strong class="note">Hinweis</strong>: <p class="para">Die interne
Kodierung oder die mit <span class="function"><a href="function.mb-regex-encoding.php" class="function">mb_regex_encoding()</a></span> festgelegte
Zeichenkodierung wird als Zeichenkodierung für diese Funktion genutzt.</p></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mb-ereg-replace-callback-seealso">
  <h3 class="title">Siehe auch</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> - Set/Get character encoding for multibyte regex</span></li>
    <li><span class="function"><a href="function.mb-ereg-replace.php" class="function" rel="rdfs-seeAlso">mb_ereg_replace()</a> - Replace regular expression with multibyte support</span></li>
    <li><a href="functions.anonymous.php" class="link">Anonymous functions</a></li>
   </ul>
  </p>
 </div>


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