Title change and some cleanup.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@26944 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Egon Schmid 2000-06-24 15:40:15 +00:00
parent 4509bcb65f
commit db03bd888b
2 changed files with 160 additions and 154 deletions

View file

@ -1,6 +1,6 @@
<reference id="ref.nis">
<title>NIS functions</title>
<titleabbrev>NIS</titleabbrev>
<title>YP/NIS Functions</title>
<titleabbrev>YP/NIS</titleabbrev>
<partintro>
<para>

View file

@ -1,5 +1,5 @@
<reference id="ref.pcre">
<title>Perl-compatible Regular Expression functions</title>
<title>Regular Expression Functions (Perl-Compatible)</title>
<titleabbrev>PCRE</titleabbrev>
<partintro>
@ -11,13 +11,11 @@
the delimiter character has to be used in the expression itself,
it needs to be escaped by backslash.
</para>
<para>
The ending delimiter may be followed by various modifiers that
affect the matching.
See <link linkend="pcre.pattern.modifiers">Pattern Modifiers</link>.
</para>
<para>
<example>
<title>Examples of valid patterns</title>
@ -28,26 +26,34 @@
</itemizedlist>
</example>
</para>
<para>
<example>
<title>Examples of invalid patterns</title>
<itemizedlist>
<listitem><simpara>/href='(.*)' - missing ending delimiter</simpara></listitem>
<listitem><simpara>/\w+\s*\w+/J - unknown modifier 'J'</simpara></listitem>
<listitem><simpara>1-\d3-\d3-\d4| - missing starting delimiter</simpara>
<listitem>
<simpara>
/href='(.*)' - missing ending delimiter
</simpara>
</listitem>
<listitem>
<simpara>
/\w+\s*\w+/J - unknown modifier 'J'
</simpara>
</listitem>
<listitem>
<simpara>
1-\d3-\d3-\d4| - missing starting delimiter
</simpara>
</listitem>
</itemizedlist>
</example>
</para>
<note>
<simpara>
The Perl-compatible regular expression functions are available in
PHP 4 and in PHP 3.0.9 and up.
</simpara>
</note>
</partintro>
<refentry id="function.preg-match">
@ -62,19 +68,21 @@
<funcdef>int <function>preg_match</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>subject</parameter></paramdef>
<paramdef>array <parameter><optional>matches</optional></parameter></paramdef>
<paramdef>array
<parameter><optional>matches</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Searches <parameter>subject</parameter> for a match to the regular
expression given in <parameter>pattern</parameter>.</para>
expression given in <parameter>pattern</parameter>.
</para>
<para>
If <parameter>matches</parameter> 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.</para>
the first captured parenthesized subpattern, and so on.
</para>
<para>
Returns true if a match for <parameter>pattern</parameter> was
found in the subject string, or false if not match was found
@ -83,17 +91,18 @@
<para>
<example>
<title>Getting the page number out of a string</title>
<programlisting>
if (preg_match("/page\s+#(\d+)/i", "Go to page #9.", $parts))
<programlisting role="php">
if (preg_match ("/page\s+#(\d+)/i", "Go to page #9.", $parts)) {
print "Next page is $parts[1]";
else
} else {
print "Page not found.";
}
</programlisting>
</example>
See also <function>preg_match_all</function>,
<function>preg_replace</function>, and
<function>preg_split</function>.</para>
<function>preg_split</function>.
</para>
</refsect1>
</refentry>
@ -110,19 +119,21 @@ else
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>subject</parameter></paramdef>
<paramdef>array <parameter>matches</parameter></paramdef>
<paramdef>int <parameter><optional>order</optional></parameter></paramdef>
<paramdef>int
<parameter><optional>order</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Searches <parameter>subject</parameter> for all matches to the regular
expression given in <parameter>pattern</parameter> and puts them in
<parameter>matches</parameter> in the order specified by
<parameter>order</parameter>.</para>
<parameter>order</parameter>.
</para>
<para>
After the first match is found, the subsequent searches are continued
on from end of the last match.</para>
on from end of the last match.
</para>
<para>
<parameter>order</parameter> can be one of two things:
<variablelist>
@ -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.
<informalexample>
<programlisting>
preg_match_all("|&lt;[^>]+>(.*)&lt;/[^>]+>|U", "&lt;b>example: &lt;/b>&lt;div align=left>a test&lt;/div>", $out, PREG_PATTERN_ORDER);
<programlisting role="php">
preg_match_all ("|&lt;[^>]+>(.*)&lt;/[^>]+>|U",
"&lt;b>example: &lt;/b>&lt;div align=left>a test&lt;/div>",
$out, PREG_PATTERN_ORDER);
print $out[0][0].", ".$out[0][1]."\n";
print $out[1][0].", ".$out[1][1]."\n"
</programlisting>
</informalexample>
This example will produce:
<informalexample>
<programlisting>
@ -149,9 +160,9 @@ print $out[1][0].", ".$out[1][1]."\n"
example: , this is a test
</programlisting>
</informalexample>
So, $out[0] contains array of strings that matched full pattern,
and $out[1] contains array of strings enclosed by tags.</para>
and $out[1] contains array of strings enclosed by tags.
</para>
</listitem>
</varlistentry>
<varlistentry>
@ -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.
<informalexample>
<programlisting>
preg_match_all("|&lt;[^>]+>(.*)&lt;/[^>]+>|U", "&lt;b>example: &lt;/b>&lt;div align=left>a test&lt;/div>", $out, PREG_SET_ORDER);
<programlisting role="php">
preg_match_all ("|&lt;[^>]+>(.*)&lt;/[^>]+>|U",
"&lt;b>example: &lt;/b>&lt;div align=left>a test&lt;/div>",
$out, PREG_SET_ORDER);
print $out[0][0].", ".$out[0][1]."\n";
print $out[1][0].", ".$out[1][1]."\n"
</programlisting>
</informalexample>
This example will produce:
<informalexample>
<programlisting>
<programlisting role="php">
&lt;b>example: &lt;/b>, example:
&lt;div align=left>this is a test&lt;/div>, this is a test
</programlisting>
</informalexample>
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.</para>
$matches[1] is the second set of matches, etc.
</para>
</listitem>
</varlistentry>
</variablelist></para>
<para>
If <parameter>order</parameter> is not specified, it is assumed
to be PREG_PATTERN_ORDER.</para>
to be PREG_PATTERN_ORDER.
</para>
<para>
Returns the number of full pattern matches, or false if
no match is found or an error occurred.</para>
no match is found or an error occurred.
</para>
<para>
<example>
<title>Getting all phone numbers out of some text.</title>
<programlisting>
preg_match_all("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",
"Call 555-1212 or 1-800-555-1212", $phones);
<programlisting role="php">
preg_match_all ("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",
"Call 555-1212 or 1-800-555-1212", $phones);
</programlisting>
</example></para>
</example>
</para>
<simpara>
See also <function>preg_match</function>,
<function>preg_replace</function>,
and <function>preg_split</function>.</simpara>
and <function>preg_split</function>.
</simpara>
</refsect1>
</refentry>
@ -228,30 +239,32 @@ preg_match_all("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",
<para>
Searches <parameter>subject</parameter> for matches to <parameter>
pattern</parameter> and replaces them with <parameter>replacement
</parameter>.</para>
</parameter>.
</para>
<para>
<parameter>replacement</parameter> may contain references of the form
<literal>\\<replaceable>n</replaceable></literal>. Every such
reference will be replaced by the text captured by the
<replaceable>n</replaceable>'th parenthesized pattern. <replaceable>n
</replaceable>can be from 0 to 99, and <literal>\\0</literal> 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.</para>
<parameter>Replacement</parameter> may contain references of the
form <literal>\\<replaceable>n</replaceable></literal>. Every
such reference will be replaced by the text captured by the
<replaceable>n</replaceable>'th parenthesized pattern.
<replaceable>n </replaceable>can be from 0 to 99, and
<literal>\\0</literal> 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.
</para>
<para>
If no matches are found in <parameter>subject</parameter>, then
it will be returned unchanged.</para>
it will be returned unchanged.
</para>
<para>
Every parameter to <function>preg_replace</function> can be an array.</para>
Every parameter to <function>preg_replace</function> can be an
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.</para>
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
@ -262,8 +275,8 @@ preg_match_all("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",
</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>
though.
</para>
<para>
<literal>/e</literal> modifier makes
<function>preg_replace</function> treat the
@ -272,41 +285,38 @@ preg_match_all("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",
that <parameter>replacement</parameter> constitutes a valid PHP
code string, otherwise PHP will complain about a parse error at
the line containing <function>preg_replace</function>.
<note>
<para>
This modifier was added in PHP 4.0.</para>
</note></para>
</para>
<para>
<example>
<title>Replacing several values</title>
<programlisting>
$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");
</programlisting>
</example>
This example will produce:
<programlisting>
$startDate = 5/27/1999
$startDate = 5/27/1999
</programlisting>
<example>
<title>Using /e modifier</title>
<programlisting>
preg_replace("/(<\/?)(\w+)([^>]*>)/e", "'\\1'.strtoupper('\\2').'\\3'", $html_body);
<programlisting role="php">
preg_replace ("/(<\/?)(\w+)([^>]*>)/e",
"'\\1'.strtoupper('\\2').'\\3'",
$html_body);
</programlisting>
<para>
This would capitalize all HTML tags in the input text.</para>
</example></para>
This would capitalize all HTML tags in the input text.
</para>
</example>
</para>
<para>
See also <function>preg_match</function>,
<function>preg_match_all</function>, and
<function>preg_split</function>.</para>
<function>preg_split</function>.
</para>
</refsect1>
</refentry>
@ -322,40 +332,43 @@ preg_replace("/(<\/?)(\w+)([^>]*>)/e", "'\\1'.strtoupper('\\2').'\\3'", $html_bo
<funcdef>array preg_split</funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>subject</parameter></paramdef>
<paramdef>int <parameter><optional>limit</optional></parameter></paramdef>
<paramdef>int <parameter><optional>flags</optional></parameter></paramdef>
<paramdef>int
<parameter><optional>limit</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<note>
<para>
Parameter <parameter>flags</parameter> was added in PHP Beta 3.</para>
Parameter <parameter>flags</parameter> was added in PHP 4 Beta 3.
</para>
</note>
<para>
Returns an array containing substrings of
<parameter>subject</parameter> split along boundaries matched by
<parameter>pattern</parameter>.</para>
<parameter>pattern</parameter>.
</para>
<para>
If <parameter>limit</parameter> is specified, then only substrings
up to <parameter>limit</parameter> are returned.</para>
up to <parameter>limit</parameter> are returned.
</para>
<para>
If flags is PREG_SPLIT_NO_EMPTY then only non-empty pieces will
be by <function>preg_split</function>.</para>
If flags is PREG_SPLIT_NO_EMPTY then only non-empty pieces will
be by <function>preg_split</function>.
</para>
<para>
<example>
<title>Getting parts of search string</title>
<programlisting>
$keywords = preg_split("/[\s,]+/", "hypertext language, programming");
<programlisting role="php">
$keywords = preg_split ("/[\s,]+/", "hypertext language, programming");
</programlisting>
</example>
See also <function>preg_match</function>,
<function>preg_match_all</function>, and
<function>preg_replace</function>.</para>
<function>preg_replace</function>.
</para>
</refsect1>
</refentry>
@ -372,22 +385,17 @@ $keywords = preg_split("/[\s,]+/", "hypertext language, programming");
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>preg_quote</function> takes <parameter>str</parameter>
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.</para>
string may contain special regex characters.
</para>
<para>
The special regular expression characters are:
<screen>. \\ + * ? [ ^ ] $ ( ) { } = ! < > | :</screen>
<note>
<para>
This function was added in PHP 3.0.9.</para>
</note></para>
</para>
</refsect1>
</refentry>
@ -415,29 +423,26 @@ $keywords = preg_split("/[\s,]+/", "hypertext language, programming");
<example>
<title><function>preg_grep</function> example</title>
<programlisting>
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
</programlisting>
</example>
<note>
<para>
This function was added in PHP 4.0.</para>
</note></para>
</para>
</refsect1>
</refentry>
<refentry id="pcre.pattern.modifiers">
<refnamediv>
<refname>Pattern Modifiers</refname>
<refpurpose>describes possible modifiers in regex
<refpurpose>Describes possible modifiers in regex
patterns</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>
The current possible PCRE modifiers are listed below. The names in
parentheses refer to internal PCRE names for these modifiers.</para>
The current possible PCRE modifiers are listed below. The names
in parentheses refer to internal PCRE names for these modifiers.
</para>
<para>
<blockquote>
<variablelist>
@ -446,10 +451,10 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the
<listitem>
<simpara>
If this modifier is set, letters in the pattern match both
upper and lower case letters.</simpara>
upper and lower case letters.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>m</emphasis> (PCRE_MULTILINE)</term>
<listitem>
@ -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
<emphasis>E</emphasis> modifier is set). This is the same as
Perl.</simpara>
Perl.
</simpara>
<simpara>
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.</simpara>
setting this modifier has no effect.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>s</emphasis> (PCRE_DOTALL)</term>
<listitem>
@ -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.</simpara>
modifier.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>x</emphasis> (PCRE_EXTENDED)</term>
<listitem>
@ -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.</simpara>
subpattern.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>e</emphasis></term>
<listitem>
@ -512,18 +517,14 @@ preg_grep("/^(\d+)?\.\d+$/", $array); // find all floating point numbers in the
If this modifier is set, <function>preg_replace</function>
does normal substitution of \\ references in the
replacement string, evaluates it as PHP code, and uses the
result for replacing the search string.</simpara>
result for replacing the search string.
</simpara>
<simpara>
Only <function>preg_replace</function> uses this modifier; it is ignored by other PCRE functions.</simpara>
<note>
<para>
This modifier was added in PHP 4.0.</para>
</note>
Only <function>preg_replace</function> uses this modifier;
it is ignored by other PCRE functions.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>A</emphasis> (PCRE_ANCHORED)</term>
<listitem>
@ -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.</simpara>
do it in Perl.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>E</emphasis> (PCRE_DOLLAR_ENDONLY)</term>
<listitem>
@ -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 <emphasis>m</emphasis>
modifier is set. There is no equivalent to this modifier in
Perl.</simpara>
Perl.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>S</emphasis></term>
<listitem>
@ -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.</simpara>
have a single fixed starting character.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>U</emphasis> (PCRE_UNGREEDY)</term>
<listitem>
@ -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.</simpara>
be set by a (?U) modifier setting within the pattern.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>X</emphasis> (PCRE_EXTRA)</term>
<listitem>
@ -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.</simpara>
modifier.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</blockquote></para>
</blockquote>
</para>
</refsect1>
</refentry>
<refentry id="pcre.pattern.syntax">
<refnamediv>
<refname>Pattern Syntax</refname>
<refpurpose>describes PCRE regex syntax</refpurpose>
<refpurpose>Describes PCRE regex syntax</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<literallayout>
@ -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.
</literallayout></refsect1>
</literallayout>
</refsect1>
<refsect1>
<title>Differences From Perl</title>
@ -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