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

eschmid Wed Jul 26 09:21:38 2000 EDT

  Modified files:
    /phpdoc/en/functions pcre.xml
  Log:
  It's now in a better shape.
  
Index: phpdoc/en/functions/pcre.xml
diff -u phpdoc/en/functions/pcre.xml:1.18 phpdoc/en/functions/pcre.xml:1.19
--- phpdoc/en/functions/pcre.xml:1.18 Wed Jul 26 08:35:42 2000
+++ phpdoc/en/functions/pcre.xml Wed Jul 26 09:21:37 2000
@@ -103,8 +103,9 @@
       <title>Getting the domain name out of a URL</title>
       <programlisting role="php">
 preg_match("/^(.*)([^\.]+\.[^\.]+)(\/.*)?/U",
-"http://www.php.net/index.html", $matches);
-echo "domain name is: ".$matches[2]."\n"; // show the second parenthesized subpattern
+ "http://www.php.net/index.html", $matches);
+// show the second parenthesized subpattern
+echo "domain name is: ".$matches[2]."\n";
       </programlisting>
      </example>
      This example will produce:
@@ -231,9 +232,9 @@
       <programlisting role="php">
 $html = "&lt;b&gt;bold text&lt;/b&gt;&lt;a href=howdy.html&gt;click me&lt;/a&gt;
 
-preg_match_all("/(&lt;w]+)[^&gt;&lt;2&gt; $html, $matches);
+preg_match_all ("/(&lt;w]+)[^&gt;&lt;2&gt; $html, $matches);
 
-for($i=0; $i&lt; count($matches[0]); $i++) {
+for ($i=0; $i&lt; count($matches[0]); $i++) {
 echo "matched: ".$matches[0][$i]."\n";
 echo "part 1: ".$matches[1][$i]."\n";
 echo "part 2: ".$matches[3][$i]."\n";
@@ -275,7 +276,9 @@
       <paramdef>mixed <parameter>pattern</parameter></paramdef>
       <paramdef>mixed <parameter>replacement</parameter></paramdef>
       <paramdef>mixed <parameter>subject</parameter></paramdef>
- <paramdef>int <parameter><optional>limit</optional></parameter></paramdef>
+ <paramdef>int
+ <parameter><optional>limit</optional></parameter>
+ </paramdef>
      </funcprototype>
     </funcsynopsis>
     <para>
@@ -307,23 +310,26 @@
      array.
     </para>
     <para>
- If <parameter>subject</parameter> is an array, then the search and
- replace is performed on every entry of <parameter>subject</parameter>,
- and the return value is an array as well.
+ If <parameter>subject</parameter> is an array, then the search
+ and replace is performed on every entry of
+ <parameter>subject</parameter>, and the return value is an array
+ as well.
+ </para>
+ <para>
+ If <parameter>pattern</parameter> and
+ <parameter>replacement</parameter> are arrays, then
+ <function>preg_replace</function> takes a value from each array
+ and uses them to do search and replace on
+ <parameter>subject</parameter>. If
+ <parameter>replacement</parameter> has fewer values than
+ <parameter>pattern</parameter>, then empty string is used for the
+ rest of replacement values. If <parameter>pattern </parameter>
+ is an array and <parameter>replacement</parameter> is a string;
+ then this replacement string is used for every value of
+ <parameter>pattern</parameter>. The converse would not make
+ sense, though.
     </para>
     <para>
- If <parameter>pattern</parameter> and <parameter>replacement</parameter>
- are arrays, then <function>preg_replace</function> takes a value from
- each array and uses them to do search and replace on
- <parameter>subject</parameter>. If <parameter>replacement</parameter>
- has fewer values than <parameter>pattern</parameter>, then empty string
- is used for the rest of replacement values. If <parameter>pattern
- </parameter> is an array and <parameter>replacement</parameter> is a
- string; then this replacement string is used for every value of
- <parameter>pattern</parameter>. The converse would not make sense,
- though.
- </para>
- <para>
      <literal>/e</literal> modifier makes
      <function>preg_replace</function> treat the
      <parameter>replacement</parameter> parameter as PHP code after
@@ -359,41 +365,40 @@
      </example>
      <example>
       <title>Convert HTML to text</title>
- <programlisting>
-
+ <programlisting role="php">
 // $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));
+$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);
+$text = preg_replace ($search, $replace, $document);
       </programlisting>
      </example>
     </para>
@@ -449,10 +454,11 @@
       <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>
+ <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
@@ -472,7 +478,9 @@
      <funcprototype>
       <funcdef>string <function>preg_quote</function></funcdef>
       <paramdef>string <parameter>str</parameter></paramdef>
- <paramdef>string <parameter><optional>delimiter</optional></parameter></paramdef>
+ <paramdef>string
+ <parameter><optional>delimiter</optional></parameter>
+ </paramdef>
      </funcprototype>
     </funcsynopsis>
     <para>
@@ -495,7 +503,7 @@
      <example>
       <title></title>
       <programlisting role="php">
-$keywords="$40 for a g3/400";
+$keywords = "$40 for a g3/400";
 $keywords = preg_quote ($keywords, "/");
 echo $keywords; // returns \$40 for a g3\/400
       </programlisting>
@@ -505,12 +513,16 @@
       <programlisting role="php">
 $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);
+$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. 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.
+ 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>
@@ -520,7 +532,9 @@
   <refentry id="function.preg-grep">
    <refnamediv>
     <refname>preg_grep</refname>
- <refpurpose>Return array entries that match the pattern</refpurpose>
+ <refpurpose>
+ Return array entries that match the pattern
+ </refpurpose>
    </refnamediv>
    <refsect1>
     <title>Description</title>
@@ -540,7 +554,7 @@
     <para>
      <example>
       <title><function>preg_grep</function> example</title>
- <programlisting>
+ <programlisting role="php">
 preg_grep ("/^(\d+)?\.\d+$/", $array); // find all floating point
                                        // numbers in the array
       </programlisting>