[PHP-DOC] cvs: phpdoc /en/functions pcre.xml From: Monte Ohrt (monte <email protected>)
Date: 07/26/00

mohrt Wed Jul 26 08:17:46 2000 EDT

  Modified files:
    /phpdoc/en/functions pcre.xml
  Log:
  added example for preg_quote()
  
  
Index: phpdoc/en/functions/pcre.xml
diff -u phpdoc/en/functions/pcre.xml:1.16 phpdoc/en/functions/pcre.xml:1.17
--- phpdoc/en/functions/pcre.xml:1.16 Wed Jul 26 07:41:04 2000
+++ phpdoc/en/functions/pcre.xml Wed Jul 26 08:17:45 2000
@@ -489,12 +489,25 @@
     </para>
     <para>
      <example>
- <title>Examples:</title>
+ <title></title>
       <programlisting role="php">
 $keywords="$40 for a g3/400";
 $keywords = preg_quote ($keywords, "/");
 echo $keywords; // returns \$40 for a g3\/400
       </programlisting>
+ </example>
+ <example>
+ <title>Replacing a word within some text</title>
+ <programlisting role="php">
+ $textbody = "This book is *very* hard to find.";
+ $word = "*very*";
+ $textbody = preg_replace("|\b".preg_quote($word)."\b|","&lt;i&gt;".$word."&lt;/i&gt;",$textbody);
+ </programlisting>
+ <para>
+ In this example, preg_quote($word) is used to keep the asterisks from having special meaning to the regular
+ expression. On a side note, the \b is an easy method of finding a word boundary, so something like
+ "is*very*big" would not be considered a match.
+ </para>
      </example>
     </para>
    </refsect1>