From 9d8e216f957b168fe60faedf476ffcd39b189d84 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Mon, 16 Jun 2003 20:03:02 +0000 Subject: [PATCH] - Layout and whitespace git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@132064 c90b9560-bf6c-de11-be94-00142212c4b1 --- .../pcre/functions/pcre.pattern.modifiers.xml | 32 ++--- reference/pcre/functions/preg-match-all.xml | 32 +++-- reference/pcre/functions/preg-match.xml | 14 ++- reference/pcre/functions/preg-quote.xml | 8 +- .../pcre/functions/preg-replace-callback.xml | 81 ++++++------- reference/pcre/functions/preg-replace.xml | 110 +++++++++--------- reference/pcre/functions/preg-split.xml | 52 ++++----- 7 files changed, 173 insertions(+), 156 deletions(-) diff --git a/reference/pcre/functions/pcre.pattern.modifiers.xml b/reference/pcre/functions/pcre.pattern.modifiers.xml index 0e536bdf4f..b111350a8c 100644 --- a/reference/pcre/functions/pcre.pattern.modifiers.xml +++ b/reference/pcre/functions/pcre.pattern.modifiers.xml @@ -1,5 +1,5 @@ - + @@ -48,8 +48,8 @@ setting this modifier has no effect. - - + + s (PCRE_DOTALL) @@ -61,8 +61,8 @@ modifier. - - + + x (PCRE_EXTENDED) @@ -79,8 +79,8 @@ subpattern. - - + + e @@ -89,18 +89,18 @@ replacement string, evaluates it as PHP code, and uses the result for replacing the search string. - + Only preg_replace uses this modifier; it is ignored by other PCRE functions. - - - - This modifier was not available in PHP3. - - + + + This modifier was not available in PHP3. + + + - - + + A (PCRE_ANCHORED) diff --git a/reference/pcre/functions/preg-match-all.xml b/reference/pcre/functions/preg-match-all.xml index dd7767904b..74d4ca5412 100644 --- a/reference/pcre/functions/preg-match-all.xml +++ b/reference/pcre/functions/preg-match-all.xml @@ -1,5 +1,5 @@ - + @@ -38,6 +38,8 @@ Orders results so that $matches[0] is an array of full pattern matches, $matches[1] is an array of strings matched by the first parenthesized subpattern, and so on. + + This example will produce: - + + example: ,
this is a test
example: , this is a test ]]> -
+ + So, $out[0] contains array of strings that matched full pattern, and $out[1] contains array of strings enclosed by tags. @@ -84,16 +88,18 @@ print $out[1][0].", ".$out[1][1]."\n"; ?> ]]>
-
- This example will produce: - - + + This example will produce: + + example: , example:
this is a test
, this is a test ]]> -
+
+
+ In this case, $matches[0] is the first set of matches, and $matches[0][0] has text matched by full pattern, $matches[0][1] has text matched by first subpattern and so on. Similarly, @@ -160,9 +166,10 @@ for ($i=0; $i< count($matches[0]); $i++) { ?> ]]> - - This example will produce: - + + This example will produce: + + bold text part 1: @@ -174,7 +181,8 @@ part 1: part 2: click me part 3: ]]> - + + See also preg_match, diff --git a/reference/pcre/functions/preg-match.xml b/reference/pcre/functions/preg-match.xml index dfbe422f60..24c68517a8 100644 --- a/reference/pcre/functions/preg-match.xml +++ b/reference/pcre/functions/preg-match.xml @@ -1,5 +1,5 @@ - + @@ -60,12 +60,14 @@ Find the string of text "php" ]]> @@ -73,6 +75,7 @@ if (preg_match ("/php/i", "PHP is the web scripting language of choice.")) { find the word "web" ]]> @@ -92,6 +96,7 @@ if (preg_match ("/\bweb\b/i", "PHP is the website scripting language of choice." Getting the domain name out of a URL ]]> This example will produce: - + + - - + See also preg_match_all, preg_replace, and diff --git a/reference/pcre/functions/preg-quote.xml b/reference/pcre/functions/preg-quote.xml index a51a78ce0c..eee8d89fcc 100644 --- a/reference/pcre/functions/preg-quote.xml +++ b/reference/pcre/functions/preg-quote.xml @@ -1,5 +1,5 @@ - + @@ -27,11 +27,11 @@ used delimiter. The special regular expression characters are: - . \\ + * ? [ ^ ] $ ( ) { } = ! < > | : + . \\ + * ? [ ^ ] $ ( ) { } = ! < > | : - + <function>preg_quote</function> example + + Italicizing a word within some text diff --git a/reference/pcre/functions/preg-replace-callback.xml b/reference/pcre/functions/preg-replace-callback.xml index f83513d62b..66e3d2f1ec 100644 --- a/reference/pcre/functions/preg-replace-callback.xml +++ b/reference/pcre/functions/preg-replace-callback.xml @@ -1,5 +1,5 @@ - + @@ -23,9 +23,9 @@ matched elements in the subject string. The callback should return the replacement string. - - <function>preg_replace_callback</function> example - + + <function>preg_replace_callback</function> example + ]]> - - - - You'll often need the callback function - for a preg_replace_callback in just one place. - In this case you can use create_function to - declare an anonymous function as callback within the call to - preg_replace_callback. By doing it this way - you have all information for the call in one place and do not - clutter the function namespace with a callback functions name - not used anywhere else. - - - <function>preg_replace_callback</function> and <function>create_function</function> - + + + + You'll often need the callback function + for a preg_replace_callback in just one place. + In this case you can use create_function to + declare an anonymous function as callback within the call to + preg_replace_callback. By doing it this way + you have all information for the call in one place and do not + clutter the function namespace with a callback functions name + not used anywhere else. + + + <function>preg_replace_callback</function> and <function>create_function</function> + \s*\w|', - create_function( - // single quotes are essential here, - // or alternative escape all $ as \$ - '$matches', - 'return strtolower($matches[0]);' - ), - $line - ); - echo $line; - } - fclose($fp); + $fp = fopen("php://stdin", "r") or die("can't read stdin"); + while (!feof($fp)) { + $line = fgets($fp); + $line = preg_replace_callback( + '|

\s*\w|', + create_function( + // single quotes are essential here, + // or alternative escape all $ as \$ + '$matches', + 'return strtolower($matches[0]);' + ), + $line + ); + echo $line; + } + fclose($fp); ?> ]]> - - + + - See also preg_replace, create_function. + See also preg_replace, + create_function. diff --git a/reference/pcre/functions/preg-replace.xml b/reference/pcre/functions/preg-replace.xml index 24457d89e1..979995dd4c 100644 --- a/reference/pcre/functions/preg-replace.xml +++ b/reference/pcre/functions/preg-replace.xml @@ -1,5 +1,5 @@ - + @@ -34,22 +34,22 @@ \\0 or $0 refers to the text matched by the whole pattern. Opening parentheses are counted from left to right (starting from 1) to obtain the number of the capturing subpattern. - - - When working with a replacement pattern where a backreference is immediately - followed by another number (i.e.: placing a literal number immediately - after a matched pattern), you cannot use the familiar \\1 - notation for your backreference. \\11, for example, - would confuse preg_replace since it does not know whether - you want the \\1 backreference followed by a literal 1, - or the \\11 backreference followed by nothing. In this case - the solution is to use \${1}1. This creates an - isolated $1 backreference, leaving the 1 - as a literal. - - + + + When working with a replacement pattern where a backreference is immediately + followed by another number (i.e.: placing a literal number immediately + after a matched pattern), you cannot use the familiar \\1 + notation for your backreference. \\11, for example, + would confuse preg_replace since it does not know whether + you want the \\1 backreference followed by a literal 1, + or the \\11 backreference followed by nothing. In this case + the solution is to use \${1}1. This creates an + isolated $1 backreference, leaving the 1 + as a literal. + + - Using backreferences followed by numeric literals. + Using backreferences followed by numeric literals Every parameter to preg_replace (except - limit) can be an array. + limit) can be an array. When using arrays with + pattern and replacement, + the keys are processed in the order they appear in the array. This is + not necessarily the same as the numerical index + order. If you use indexes to identify which + pattern should be replaced by which + replacement, you should perform a + ksort on each array prior to calling + preg_replace. - - - When using arrays with pattern and - replacement, the keys are processed - in the order they appear in the array. This is - not necessarily the same as the numerical - index order. If you use indexes to identify which - pattern should be replaced by which - replacement, you should perform a - ksort on each array prior to calling - preg_replace. - - Using indexed arrays with <function>preg_replace</function> @@ -143,63 +138,71 @@ The slow black bear jumped over the lazy dog. as well. - If pattern and - replacement are arrays, then - preg_replace takes a value from each array - and uses them to do search and replace on - subject. If - replacement has fewer values than - pattern, then empty string is used for the - rest of replacement values. If pattern - is an array and replacement is a string, - then this replacement string is used for every value of - pattern. The converse would not make - sense, though. + If pattern and replacement + are arrays, then preg_replace takes a value from + each array and uses them to do search and replace on + subject. If replacement + has fewer values than pattern, then empty string + is used for the rest of replacement values. If pattern + is an array and replacement is a + string, then this replacement string is used for every value of + pattern. The converse would not make sense, + though. - /e modifier makes - preg_replace treat the - replacement parameter as PHP code after - the appropriate references substitution is done. Tip: make sure - that replacement constitutes a valid PHP - code string, otherwise PHP will complain about a parse error at - the line containing preg_replace. + /e modifier makes preg_replace + treat the replacement parameter as PHP code after + the appropriate references substitution is done. Tip: make sure that + replacement constitutes a valid PHP code string, + otherwise PHP will complain about a parse error at the line containing + preg_replace. Replacing several values ]]> - - This example will produce: - + + This example will produce: + + - + + + + Using /e modifier ]*>)/e", "'\\1'.strtoupper('\\2').'\\3'", $html_body); +?> ]]> This would capitalize all HTML tags in the input text. + + Convert HTML to text ]]> diff --git a/reference/pcre/functions/preg-split.xml b/reference/pcre/functions/preg-split.xml index 0b35fc84e3..45de2d33f9 100644 --- a/reference/pcre/functions/preg-split.xml +++ b/reference/pcre/functions/preg-split.xml @@ -1,5 +1,5 @@ - + @@ -66,44 +66,44 @@ - - - <function>preg_split</function> example : Get the parts of a search string - + + + <function>preg_split</function> example : Get the parts of a search string + - - + + - - Splitting a string into component characters - + + Splitting a string into component characters + - - + + - - Splitting a string into matches and their offsets - + + Splitting a string into matches and their offsets + - - - will yield - - + + + will yield: + + - - + + @@ -136,15 +136,11 @@ Array - See also - spliti, - split, - implode, - preg_match, + See also spliti, split, + implode, preg_match, preg_match_all, and preg_replace. -