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/fr/function.preg-filter.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = 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-filter.php',
   
1 => 'preg_filter',
  ),
 
'up' =>
  array (
   
0 => 'ref.pcre.php',
   
1 => 'Fonctions PCRE',
  ),
 
'prev' =>
  array (
   
0 => 'ref.pcre.php',
   
1 => 'Fonctions PCRE',
  ),
 
'next' =>
  array (
   
0 => 'function.preg-grep.php',
   
1 => 'preg_grep',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.preg-filter" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">preg_filter</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0)</p><p class="refpurpose"><span class="refname">preg_filter</span> &mdash; <span class="dc-title">Recherche et remplace avec une expression rationnelle</span></p>

 </div>

 <a name="function.preg-filter.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>preg_filter</b></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.php#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$pattern</tt></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.php#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$replacement</tt></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.php#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$subject</tt></span>
   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$limit</tt><span class="initializer">= -1</span></span>
   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter reference">&amp;$count</tt></span>
  ]] )</div>

  <p class="para rdfs-comment">
   <b>preg_filter()</b> est identique à
   <a href="function.preg-replace.php" class="function">preg_replace()</a>, mais elle ne fait que retourner
   les occurrences trouvées. Pour plus de détails sur le fonctionnement
   de cette fonction, voyez <a href="function.preg-replace.php" class="function">preg_replace()</a>.
  </p>
 </div>


 <a name="function.preg-filter.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

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

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

      <p class="para">
      </p>
     </dd>

   
    <dt class="varlistentry">

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

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

      <p class="para">
      </p>
     </dd>

   
    <dt class="varlistentry">

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

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

      <p class="para">
      </p>
     </dd>

   
    <dt class="varlistentry">

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

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

      <p class="para">
      </p>
     </dd>

   
    <dt class="varlistentry">

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

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

      <p class="para">
      </p>
     </dd>

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


 <a name="function.preg-filter.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne un <a href="language.types.array.php" class="link">tableau</a> si le paramètre <i><tt class="parameter">subject</tt></i>

   est de type <a href="language.types.array.php" class="link">tableau</a> ou une <a href="language.types.string.php" class="link">chaîne de caractères</a> autrement.
  </p>
  <p class="para">
   Si des occurrences sont trouvées, le nouveau
   <i><tt class="parameter">subject</tt></i>
 sera retourné, et sinon,
   <i><tt class="parameter">subject</tt></i>
 sera retourné inchangé, ou
   <b><tt class="constant">NULL</tt></b> si une erreur est survenue.
  </p>
 </div>


 <a name="function.preg-filter.examples"></a><div class="refsect1 examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Exemple #1
     Exemple de comparaison de <b>preg_filter()</b>
     avec <a href="function.preg-replace.php" class="function">preg_replace()</a>
    </b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$subject&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'1'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'a'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'2'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'b'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'3'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'A'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'B'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'4'</span><span style="color: #007700">);&nbsp;<br /></span><span style="color: #0000BB">$pattern&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'/\d/'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'/[a-z]/'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'/[1a]/'</span><span style="color: #007700">);&nbsp;<br /></span><span style="color: #0000BB">$replace&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'A:$0'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'B:$0'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'C:$0'</span><span style="color: #007700">);&nbsp;<br /><br />echo&nbsp;</span><span style="color: #DD0000">"preg_filter&nbsp;renvoie\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">preg_filter</span><span style="color: #007700">(</span><span style="color: #0000BB">$pattern</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$replace</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$subject</span><span style="color: #007700">));&nbsp;<br /><br />echo&nbsp;</span><span style="color: #DD0000">"preg_replace&nbsp;renvoie\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">preg_replace</span><span style="color: #007700">(</span><span style="color: #0000BB">$pattern</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$replace</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$subject</span><span style="color: #007700">));&nbsp;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents para"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
preg_filter renvoie
Array
(
    [0] =&gt; A:C:1
    [1] =&gt; B:C:a
    [2] =&gt; A:2
    [3] =&gt; B:b
    [4] =&gt; A:3
    [7] =&gt; A:4
)
preg_replace renvoie
Array
(
    [0] =&gt; A:C:1
    [1] =&gt; B:C:a
    [2] =&gt; A:2
    [3] =&gt; B:b
    [4] =&gt; A:3
    [5] =&gt; A
    [6] =&gt; B
    [7] =&gt; A:4
)
</pre></div>
    </div>
   </div><p>
  </p>
 </div>


 <a name="function.preg-filter.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.preg-replace.php" class="function" rel="rdfs-seeAlso">preg_replace()</a> - Rechercher et remplacer par expression rationnelle standard</li>
    <li class="member"><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</li>
    <li class="member"><a href="function.preg-match.php" class="function" rel="rdfs-seeAlso">preg_match()</a> - Expression rationnelle standard</li>
    <li class="member"><a href="function.preg-split.php" class="function" rel="rdfs-seeAlso">preg_split()</a> - Éclate une chaîne par expression rationnelle</li>
   </ul><p>
  </p>
 </div>

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