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-quote.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-quote.php',
   
1 => 'preg_quote',
  ),
 
'up' =>
  array (
   
0 => 'ref.pcre.php',
   
1 => 'Fonctions PCRE',
  ),
 
'prev' =>
  array (
   
0 => 'function.preg-match.php',
   
1 => 'preg_match',
  ),
 
'next' =>
  array (
   
0 => 'function.preg-replace-callback.php',
   
1 => 'preg_replace_callback',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.preg-quote" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">preg_quote</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">preg_quote</span> &mdash; <span class="dc-title">Protection des caractères spéciaux des expressions rationnelles</span></p>

 </div>

 <a name="function.preg-quote.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><b>preg_quote</b></span>
    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$str</tt></span>
  [, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$delimiter</tt><span class="initializer">= NULL</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   <b>preg_quote()</b> ajoute un antislash devant tous
   les caractères de la chaîne <i><tt class="parameter">str</tt></i>
.
   Cela est très utile si vous avez une chaîne qui va
   servir de masque, mais qui est générée durant
   l&#039;exécution.
  </p>
  <p class="para">
   Les caractères spéciaux qui seront protégés sont les suivants :
   <i>. \ + * ? [ ^ ] $ ( ) { } = ! &lt; &gt; | : -</i>
  </p>
 </div>


 <a name="function.preg-quote.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">str</tt></i>
</span>

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

      <p class="para">
       La chaîne d&#039;entrée.
      </p>
     </dd>

   
    <dt class="varlistentry">

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

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

      <p class="para">
       Si l&#039;argument optionnel <i><tt class="parameter">delimiter</tt></i>
 est fourni,
       il sera aussi échappé. Ceci est pratique pour échapper
       le délimiteur requis par les fonctions PCRE. Le slash / est le
       délimiteur le plus répandu.
      </p>
     </dd>

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


 <a name="function.preg-quote.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne la chaîne protégée.
  </p>
 </div>


 <a name="function.preg-quote.changelog"></a><div class="refsect1 changelog">
  <h3 class="title">Historique</h3>
  <p class="para">
   </p><table class="doctable informaltable">
   
     <thead valign="middle">
      <tr valign="middle">
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody valign="middle" class="tbody">
      <tr valign="middle">
       <td align="left">5.3.0</td>
       <td align="left">
        Le caractère <i>-</i> est maintenant protégé.
       </td>
      </tr>

     </tbody>
   
   </table>
<p>
  </p>
 </div>


 <a name="function.preg-quote.examples"></a><div class="refsect1 examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Exemple #1 Exemple avec <b>preg_quote()</b></b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$keywords&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'$40&nbsp;pour&nbsp;un&nbsp;g3/400'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$keywords&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">preg_quote</span><span style="color: #007700">(</span><span style="color: #0000BB">$keywords</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'/'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$keywords</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;retourne&nbsp;\$40&nbsp;pour&nbsp;un&nbsp;g3\/400<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
  <p class="para">
   </p><div class="example">
    <p><b>Exemple #2 Mise en italique d&#039;un mot dans un texte</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Dans&nbsp;cet&nbsp;exemple,&nbsp;preg_quote($word)&nbsp;sert&nbsp;à&nbsp;éviter&nbsp;que&nbsp;les&nbsp;astérisques<br />//&nbsp;prennent&nbsp;une&nbsp;valeur&nbsp;particulière&nbsp;dans&nbsp;l'expression&nbsp;rationnelle.<br /><br /></span><span style="color: #0000BB">$textbody&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Ce&nbsp;livre&nbsp;est&nbsp;*très*&nbsp;difficile&nbsp;à&nbsp;trouver."</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$word&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"*très*"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$textbody&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">preg_replace&nbsp;</span><span style="color: #007700">(</span><span style="color: #DD0000">"/"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">preg_quote</span><span style="color: #007700">(</span><span style="color: #0000BB">$word</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"/"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"&lt;i&gt;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$word&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"&lt;/i&gt;"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$textbody</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

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


 <a name="function.preg-quote.notes"></a><div class="refsect1 notes">
  <h3 class="title">Notes</h3>
  <blockquote><p><b class="note">Note</b>: <span class="simpara">Cette fonction gère les chaînes
binaires.</span></p></blockquote>
 </div>


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