diff --git a/functions/nis.xml b/functions/nis.xml index d9501c3104..e3739fd48a 100644 --- a/functions/nis.xml +++ b/functions/nis.xml @@ -1,6 +1,6 @@ - NIS functions - NIS + YP/NIS Functions + YP/NIS diff --git a/functions/pcre.xml b/functions/pcre.xml index dca7cb86d1..bf597f96c5 100644 --- a/functions/pcre.xml +++ b/functions/pcre.xml @@ -1,5 +1,5 @@ - Perl-compatible Regular Expression functions + Regular Expression Functions (Perl-Compatible) PCRE @@ -11,13 +11,11 @@ the delimiter character has to be used in the expression itself, it needs to be escaped by backslash. - The ending delimiter may be followed by various modifiers that affect the matching. See Pattern Modifiers. - Examples of valid patterns @@ -28,26 +26,34 @@ - Examples of invalid patterns - /href='(.*)' - missing ending delimiter - /\w+\s*\w+/J - unknown modifier 'J' - 1-\d3-\d3-\d4| - missing starting delimiter + + + /href='(.*)' - missing ending delimiter + + + + + /\w+\s*\w+/J - unknown modifier 'J' + + + + + 1-\d3-\d3-\d4| - missing starting delimiter + - The Perl-compatible regular expression functions are available in PHP 4 and in PHP 3.0.9 and up. - @@ -62,19 +68,21 @@ int preg_match string pattern string subject - array matches + array + matches + Searches subject for a match to the regular - expression given in pattern. - + expression given in pattern. + If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that match the full pattern, $matches[1] will have the text that matched - the first captured parenthesized subpattern, and so on. - + the first captured parenthesized subpattern, and so on. + Returns true if a match for pattern was found in the subject string, or false if not match was found @@ -83,17 +91,18 @@ Getting the page number out of a string - -if (preg_match("/page\s+#(\d+)/i", "Go to page #9.", $parts)) + +if (preg_match ("/page\s+#(\d+)/i", "Go to page #9.", $parts)) { print "Next page is $parts[1]"; -else +} else { print "Page not found."; +} - See also preg_match_all, preg_replace, and - preg_split. + preg_split. + @@ -110,19 +119,21 @@ else string pattern string subject array matches - int order + int + order + Searches subject for all matches to the regular expression given in pattern and puts them in matches in the order specified by - order. - + order. + After the first match is found, the subsequent searches are continued - on from end of the last match. - + on from end of the last match. + order can be one of two things: @@ -133,15 +144,15 @@ else 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. - - -preg_match_all("|<[^>]+>(.*)</[^>]+>|U", "<b>example: </b><div align=left>a test</div>", $out, PREG_PATTERN_ORDER); + +preg_match_all ("|<[^>]+>(.*)</[^>]+>|U", + "<b>example: </b><div align=left>a test</div>", + $out, PREG_PATTERN_ORDER); print $out[0][0].", ".$out[0][1]."\n"; print $out[1][0].", ".$out[1][1]."\n" - This example will produce: @@ -149,9 +160,9 @@ print $out[1][0].", ".$out[1][1]."\n" 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. + and $out[1] contains array of strings enclosed by tags. + @@ -161,52 +172,52 @@ example: , this is a test Orders results so that $matches[0] is an array of first set of matches, $matches[1] is an array of second set of matches, and so on. - - -preg_match_all("|<[^>]+>(.*)</[^>]+>|U", "<b>example: </b><div align=left>a test</div>", $out, PREG_SET_ORDER); + +preg_match_all ("|<[^>]+>(.*)</[^>]+>|U", + "<b>example: </b><div align=left>a test</div>", + $out, PREG_SET_ORDER); print $out[0][0].", ".$out[0][1]."\n"; print $out[1][0].", ".$out[1][1]."\n" - This example will produce: - + <b>example: </b>, example: <div align=left>this is a test</div>, 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, - $matches[1] is the second set of matches, etc. + $matches[1] is the second set of matches, etc. + - If order is not specified, it is assumed - to be PREG_PATTERN_ORDER. - + to be PREG_PATTERN_ORDER. + Returns the number of full pattern matches, or false if - no match is found or an error occurred. - + no match is found or an error occurred. + Getting all phone numbers out of some text. - -preg_match_all("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x", - "Call 555-1212 or 1-800-555-1212", $phones); + +preg_match_all ("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x", + "Call 555-1212 or 1-800-555-1212", $phones); - - + + See also preg_match, preg_replace, - and preg_split. + and preg_split. + @@ -228,30 +239,32 @@ preg_match_all("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x", Searches subject for matches to pattern and replaces them with replacement - . - + . + - replacement may contain references of the form - \\n. Every such - reference will be replaced by the text captured by the - n'th parenthesized pattern. n - can be from 0 to 99, and \\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. - + Replacement may contain references of the + form \\n. Every + such reference will be replaced by the text captured by the + n'th parenthesized pattern. + n can be from 0 to 99, and + \\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. + If no matches are found in subject, then - it will be returned unchanged. - + it will be returned unchanged. + - Every parameter to preg_replace can be an array. - + Every parameter to preg_replace can be an + array. + If subject is an array, then the search and replace is performed on every entry of subject, - and the return value is an array as well. - + and the return value is an array as well. + If pattern and replacement are arrays, then preg_replace takes a value from @@ -262,8 +275,8 @@ preg_match_all("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x", 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. - + though. + /e modifier makes preg_replace treat the @@ -272,41 +285,38 @@ preg_match_all("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x", that replacement constitutes a valid PHP code string, otherwise PHP will complain about a parse error at the line containing preg_replace. - - - This modifier was added in PHP 4.0. - - + Replacing several values -$patterns = array("/(19|20\d{2})-(\d{1,2})-(\d{1,2})/", "/^\s*{(\w+)}\s*=/"); -$replace = array("\\3/\\4/\\1", "$\\1 ="); -print preg_replace($patterns, $replace, "{startDate} = 1999-5-27"); +$patterns = array ("/(19|20\d{2})-(\d{1,2})-(\d{1,2})/", + "/^\s*{(\w+)}\s*=/"); +$replace = array ("\\3/\\4/\\1", "$\\1 ="); +print preg_replace ($patterns, $replace, "{startDate} = 1999-5-27"); - This example will produce: - - $startDate = 5/27/1999 +$startDate = 5/27/1999 - Using /e modifier - -preg_replace("/(<\/?)(\w+)([^>]*>)/e", "'\\1'.strtoupper('\\2').'\\3'", $html_body); + +preg_replace ("/(<\/?)(\w+)([^>]*>)/e", + "'\\1'.strtoupper('\\2').'\\3'", + $html_body); - - This would capitalize all HTML tags in the input text. - - + This would capitalize all HTML tags in the input text. + + + See also preg_match, preg_match_all, and - preg_split. + preg_split. + @@ -322,40 +332,43 @@ preg_replace("/(<\/?)(\w+)([^>]*>)/e", "'\\1'.strtoupper('\\2').'\\3'", $html_bo array preg_split string pattern string subject - int limit - int flags + int + limit + + int + flags + - - Parameter flags was added in PHP Beta 3. + Parameter flags was added in PHP 4 Beta 3. + - Returns an array containing substrings of subject split along boundaries matched by - pattern. - + pattern. + If limit is specified, then only substrings - up to limit are returned. - + up to limit are returned. + - If flags is PREG_SPLIT_NO_EMPTY then only non-empty pieces will - be by preg_split. - + If flags is PREG_SPLIT_NO_EMPTY then only non-empty pieces will + be by preg_split. + Getting parts of search string - -$keywords = preg_split("/[\s,]+/", "hypertext language, programming"); + +$keywords = preg_split ("/[\s,]+/", "hypertext language, programming"); - See also preg_match, preg_match_all, and - preg_replace. + preg_replace. + @@ -372,22 +385,17 @@ $keywords = preg_split("/[\s,]+/", "hypertext language, programming"); string str - preg_quote takes str and puts a backslash in front of every character that is part of the regular expression syntax. This is useful if you have a run-time string that you need to match in some text and the - string may contain special regex characters. - + string may contain special regex characters. + The special regular expression characters are: . \\ + * ? [ ^ ] $ ( ) { } = ! < > | : - - - - This function was added in PHP 3.0.9. - + @@ -415,29 +423,26 @@ $keywords = preg_split("/[\s,]+/", "hypertext language, programming"); <function>preg_grep</function> example -preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the array +preg_grep ("/^(\d+)?\.\d+$/", $array); // find all floating point + // numbers in the array - - - - This function was added in PHP 4.0. - + Pattern Modifiers - describes possible modifiers in regex + Describes possible modifiers in regex patterns Description - The current possible PCRE modifiers are listed below. The names in - parentheses refer to internal PCRE names for these modifiers. - + The current possible PCRE modifiers are listed below. The names + in parentheses refer to internal PCRE names for these modifiers. +
@@ -446,10 +451,10 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the If this modifier is set, letters in the pattern match both - upper and lower case letters. + upper and lower case letters. + - m (PCRE_MULTILINE) @@ -461,8 +466,8 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the line" metacharacter ($) matches only at the end of the string, or before a terminating newline (unless E modifier is set). This is the same as - Perl. - + Perl. + When this modifier is set, the "start of line" and "end of line" constructs match immediately following or immediately @@ -470,10 +475,10 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the well as at the very start and end. This is equivalent to Perl's /m modifier. If there are no "\n" characters in a subject string, or no occurrences of ^ or $ in a pattern, - setting this modifier has no effect. + setting this modifier has no effect. + - s (PCRE_DOTALL) @@ -483,10 +488,10 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this - modifier. + modifier. + - x (PCRE_EXTENDED) @@ -501,10 +506,10 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the to data characters. Whitespace characters may never appear within special character sequences in a pattern, for example within the sequence (?( which introduces a conditional - subpattern. + subpattern. + - e @@ -512,18 +517,14 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the If this modifier is set, preg_replace does normal substitution of \\ references in the replacement string, evaluates it as PHP code, and uses the - result for replacing the search string. - + result for replacing the search string. + - Only preg_replace uses this modifier; it is ignored by other PCRE functions. - - - - This modifier was added in PHP 4.0. - + Only preg_replace uses this modifier; + it is ignored by other PCRE functions. + - A (PCRE_ANCHORED) @@ -533,10 +534,10 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the start of the string which is being searched (the "subject string"). This effect can also be achieved by appropriate constructs in the pattern itself, which is the only way to - do it in Perl. + do it in Perl. + - E (PCRE_DOLLAR_ENDONLY) @@ -547,10 +548,10 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the character if it is a newline (but not before any other newlines). This modifier is ignored if m modifier is set. There is no equivalent to this modifier in - Perl. + Perl. + - S @@ -560,10 +561,10 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the the time taken for matching. If this modifier is set, then this extra analysis is performed. At present, studying a pattern is useful only for non-anchored patterns that do not - have a single fixed starting character. + have a single fixed starting character. + - U (PCRE_UNGREEDY) @@ -571,10 +572,10 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the This modifier inverts the "greediness" of the quantifiers so that they are not greedy by default, but become greedy if followed by "?". It is not compatible with Perl. It can also - be set by a (?U) modifier setting within the pattern. + be set by a (?U) modifier setting within the pattern. + - X (PCRE_EXTRA) @@ -586,19 +587,23 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the expansion. By default, as in Perl, a backslash followed by a letter with no special meaning is treated as a literal. There are at present no other features controlled by this - modifier. + modifier. + -
+ +
+ Pattern Syntax - describes PCRE regex syntax + Describes PCRE regex syntax + Description @@ -606,7 +611,8 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the expression pattern matching using the same syntax and semantics as Perl 5, with just a few differences (see below). The current implementation corresponds to Perl 5.005. - + + Differences From Perl @@ -1692,7 +1698,7 @@ sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil -sgml-default-dtd-file:"../manual.ced" +sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil