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

mohrt Wed Jul 26 08:35:42 2000 EDT

  Modified files:
    /phpdoc/en/functions pcre.xml
  Log:
  clean up pcre examples formatting
  
  
Index: phpdoc/en/functions/pcre.xml
diff -u phpdoc/en/functions/pcre.xml:1.17 phpdoc/en/functions/pcre.xml:1.18
--- phpdoc/en/functions/pcre.xml:1.17 Wed Jul 26 08:17:45 2000
+++ phpdoc/en/functions/pcre.xml Wed Jul 26 08:35:42 2000
@@ -102,14 +102,14 @@
      <example>
       <title>Getting the domain name out of a URL</title>
       <programlisting role="php">
- preg_match("/^(.*)([^\.]+\.[^\.]+)(\/.*)?/U",
+preg_match("/^(.*)([^\.]+\.[^\.]+)(\/.*)?/U",
 "http://www.php.net/index.html", $matches);
- echo "domain name is: ".$matches[2]."\n";
+echo "domain name is: ".$matches[2]."\n"; // show the second parenthesized subpattern
       </programlisting>
      </example>
      This example will produce:
      <programlisting>
- domain name is: php.net
+domain name is: php.net
      </programlisting>
      See also <function>preg_match_all</function>,
      <function>preg_replace</function>, and
@@ -354,46 +354,46 @@
               $html_body);
       </programlisting>
       <para>
- This would capitalize all HTML tags in the input text.
+This would capitalize all HTML tags in the input text.
       </para>
      </example>
      <example>
       <title>Convert HTML to text</title>
       <programlisting>
-
- // $document should contain an HTML document.
- // This will remove HTML tags, javascript sections
- // and white space. It will also convert some
- // common HTML entities to their text equivalent.
-
- $search = array("'&lt;script[^&gt;]*?&gt;.*?&lt;/script&gt;'si", // strip out javascript
- "'&lt;[\/\!]*?[^&lt;&gt;]*?&gt;'si", // strip out html tags
- "'([\r\n])[\s]+'", // strip out white space
- "'&amp;(quote|#34);'i", // replace html entities
- "'&amp;(amp|#38);'i",
- "'&amp;(lt|#60);'i",
- "'&amp;(gt|#62);'i",
- "'&amp;(nbsp|#160);'i",
- "'&amp;(iexcl|#161);'i",
- "'&amp;(cent|#162);'i",
- "'&amp;(pound|#163);'i",
- "'&amp;(copy|#169);'i"
- );
-
- $replace = array( "",
- "",
- "\\1",
- "\"",
- "&amp;",
- "&lt;",
- "&gt;",
- " ",
- chr(161),
- chr(162),
- chr(163),
- chr(169));
 
- $text = preg_replace($search,$replace,$document);
+// $document should contain an HTML document.
+// This will remove HTML tags, javascript sections
+// and white space. It will also convert some
+// common HTML entities to their text equivalent.
+
+$search = array("'&lt;script[^&gt;]*?&gt;.*?&lt;/script&gt;'si", // strip out javascript
+ "'&lt;[\/\!]*?[^&lt;&gt;]*?&gt;'si", // strip out html tags
+ "'([\r\n])[\s]+'", // strip out white space
+ "'&amp;(quote|#34);'i", // replace html entities
+ "'&amp;(amp|#38);'i",
+ "'&amp;(lt|#60);'i",
+ "'&amp;(gt|#62);'i",
+ "'&amp;(nbsp|#160);'i",
+ "'&amp;(iexcl|#161);'i",
+ "'&amp;(cent|#162);'i",
+ "'&amp;(pound|#163);'i",
+ "'&amp;(copy|#169);'i"
+ );
+
+$replace = array( "",
+ "",
+ "\\1",
+ "\"",
+ "&amp;",
+ "&lt;",
+ "&gt;",
+ " ",
+ chr(161),
+ chr(162),
+ chr(163),
+ chr(169));
+
+$text = preg_replace($search,$replace,$document);
       </programlisting>
      </example>
     </para>
@@ -449,6 +449,10 @@
       <programlisting role="php">
 $keywords = preg_split ("/[\s,]+/", "hypertext language, programming");
       </programlisting>
+ <para>
+This example splits the text by any number of spaces or commas. So the resulting $keywords array would be
+("hypertext", "language", "programming")
+ </para>
      </example>
      See also <function>preg_match</function>,
      <function>preg_match_all</function>, and
@@ -497,16 +501,16 @@
       </programlisting>
      </example>
      <example>
- <title>Replacing a word within some text</title>
+ <title>Italicizing 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);
+$textbody = "This book is *very* difficult 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.
+In this example, preg_quote($word) is used to keep the asterisks from having special meaning to the regular
+expression. The \b is recognized by pcre to find a word boundary, so only whole words match. This way something like "is*very*difficult" would not be
+considered a match.
       </para>
      </example>
     </para>