Date: 07/26/00
- Next message: Vlad Krupin: "[PHP-DOC] cvs: phpdoc /en/functions pspell.xml"
- Previous message: Monte Ohrt: "[PHP-DOC] cvs: phpdoc /en/functions pcre.xml"
- Next in thread: Monte Ohrt: "[PHP-DOC] cvs: phpdoc /en/functions pcre.xml"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 = "<b>bold text</b><a href=howdy.html>click me</a>
-preg_match_all("/(<w]+)[^><2> $html, $matches);
+preg_match_all ("/(<w]+)[^><2> $html, $matches);
-for($i=0; $i< count($matches[0]); $i++) {
+for ($i=0; $i< 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("'<script[^>]*?>.*?</script>'si", // strip out javascript
- "'<[\/\!]*?[^<>]*?>'si", // strip out html tags
- "'([\r\n])[\s]+'", // strip out white space
- "'&(quote|#34);'i", // replace html entities
- "'&(amp|#38);'i",
- "'&(lt|#60);'i",
- "'&(gt|#62);'i",
- "'&(nbsp|#160);'i",
- "'&(iexcl|#161);'i",
- "'&(cent|#162);'i",
- "'&(pound|#163);'i",
- "'&(copy|#169);'i"
- );
-
-$replace = array( "",
- "",
- "\\1",
- "\"",
- "&",
- "<",
- ">",
- " ",
- chr(161),
- chr(162),
- chr(163),
- chr(169));
+$search = array ("'<script[^>]*?>.*?</script>'si",
+ // Strip out javascript
+ "'<[\/\!]*?[^<>]*?>'si", // Strip out html tags
+ "'([\r\n])[\s]+'", // Strip out white space
+ "'&(quote|#34);'i", // Replace html entities
+ "'&(amp|#38);'i",
+ "'&(lt|#60);'i",
+ "'&(gt|#62);'i",
+ "'&(nbsp|#160);'i",
+ "'&(iexcl|#161);'i",
+ "'&(cent|#162);'i",
+ "'&(pound|#163);'i",
+ "'&(copy|#169);'i");
+
+$replace = array ("",
+ "",
+ "\\1",
+ "\"",
+ "&",
+ "<",
+ ">",
+ " ",
+ 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|","<i>".$word."</i>",$textbody);
+$textbody = preg_replace ("|\b".preg_quote($word)."\b|",
+ "<i>".$word."</i>",
+ $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>
- Next message: Vlad Krupin: "[PHP-DOC] cvs: phpdoc /en/functions pspell.xml"
- Previous message: Monte Ohrt: "[PHP-DOC] cvs: phpdoc /en/functions pcre.xml"
- Next in thread: Monte Ohrt: "[PHP-DOC] cvs: phpdoc /en/functions pcre.xml"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

