WS, preparing for new doc style

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@228784 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Mehdi Achour 2007-02-02 22:09:12 +00:00
parent 79812ccb2d
commit 64a1c7cc9e
7 changed files with 498 additions and 507 deletions

View file

@ -1,56 +1,53 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.6 $ -->
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 -->
<refentry id="function.preg-grep">
<refnamediv>
<refname>preg_grep</refname>
<refpurpose>
Return array entries that match the pattern
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>array</type><methodname>preg_grep</methodname>
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
<methodparam><type>array</type><parameter>input</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter></methodparam>
</methodsynopsis>
<!-- $Revision: 1.7 $ -->
<refentry id="function.preg-grep">
<refnamediv>
<refname>preg_grep</refname>
<refpurpose>Return array entries that match the pattern</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>array</type><methodname>preg_grep</methodname>
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
<methodparam><type>array</type><parameter>input</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter></methodparam>
</methodsynopsis>
<para>
<function>preg_grep</function> returns the array consisting of
the elements of the <parameter>input</parameter> array that match
the given <parameter>pattern</parameter>.
</para>
<para>
<parameter>flags</parameter> can be the following flag:
<variablelist>
<varlistentry>
<term>PREG_GREP_INVERT</term>
<listitem>
<simpara>
If this flag is passed, <function>preg_grep</function> returns the
elements of the input array that do <emphasis>not</emphasis> match
the given <parameter>pattern</parameter>.
This flag is available since PHP 4.2.0.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
<function>preg_grep</function> returns the array consisting of
the elements of the <parameter>input</parameter> array that match
the given <parameter>pattern</parameter>.
</para>
<para>
Since PHP 4.0.4, the results returned by <function>preg_grep</function>
are indexed using the keys from the input array. If this behavior is
undesirable, use <function>array_values</function> on the array returned by
<function>preg_grep</function> to reindex the values.
</para>
<para>
<parameter>flags</parameter> can be the following flag:
<variablelist>
<varlistentry>
<term>PREG_GREP_INVERT</term>
<listitem>
<simpara>
If this flag is passed, <function>preg_grep</function> returns the
elements of the input array that do <emphasis>not</emphasis> match
the given <parameter>pattern</parameter>.
This flag is available since PHP 4.2.0.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
<example>
<title><function>preg_grep</function> example</title>
<programlisting role="php">
<para>
Since PHP 4.0.4, the results returned by <function>preg_grep</function>
are indexed using the keys from the input array. If this behavior is
undesirable, use <function>array_values</function> on the array returned by
<function>preg_grep</function> to reindex the values.
</para>
<para>
<example>
<title><function>preg_grep</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
// return all array elements
@ -58,11 +55,11 @@
$fl_array = preg_grep("/^(\d+)?\.\d+$/", $array);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:

View file

@ -1,180 +1,179 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.20 $ -->
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 -->
<refentry id="function.preg-match-all">
<refnamediv>
<refname>preg_match_all</refname>
<refpurpose>Perform a global regular expression match</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>preg_match_all</methodname>
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
<methodparam><type>string</type><parameter>subject</parameter></methodparam>
<methodparam><type>array</type><parameter role="reference">matches</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>offset</parameter></methodparam>
</methodsynopsis>
<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>flags</parameter>.
</para>
<para>
After the first match is found, the subsequent searches are continued
on from end of the last match.
</para>
<para>
<parameter>flags</parameter> can be a combination of the following flags
(note that it doesn't make sense to use
<constant>PREG_PATTERN_ORDER</constant> together with
<constant>PREG_SET_ORDER</constant>):
<variablelist>
<varlistentry>
<term>PREG_PATTERN_ORDER</term>
<listitem>
<para>
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.
</para>
<para>
<informalexample>
<programlisting role="php">
<!-- $Revision: 1.21 $ -->
<refentry id="function.preg-match-all">
<refnamediv>
<refname>preg_match_all</refname>
<refpurpose>Perform a global regular expression match</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>preg_match_all</methodname>
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
<methodparam><type>string</type><parameter>subject</parameter></methodparam>
<methodparam><type>array</type><parameter role="reference">matches</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>offset</parameter></methodparam>
</methodsynopsis>
<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>flags</parameter>.
</para>
<para>
After the first match is found, the subsequent searches are continued
on from end of the last match.
</para>
<para>
<parameter>flags</parameter> can be a combination of the following flags
(note that it doesn't make sense to use
<constant>PREG_PATTERN_ORDER</constant> together with
<constant>PREG_SET_ORDER</constant>):
<variablelist>
<varlistentry>
<term>PREG_PATTERN_ORDER</term>
<listitem>
<para>
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.
</para>
<para>
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
preg_match_all("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=left>this is a test</div>",
preg_match_all("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=left>this is a test</div>",
$out, PREG_PATTERN_ORDER);
echo $out[0][0] . ", " . $out[0][1] . "\n";
echo $out[1][0] . ", " . $out[1][1] . "\n";
?>
]]>
</programlisting>
<para>
This example will produce:
</para>
<screen role="html">
</programlisting>
<para>
This example will produce:
</para>
<screen role="html">
<![CDATA[
<b>example: </b>, <div align=left>this is a test</div>
example: , this is a test
]]>
</screen>
<para>
So, $out[0] contains array of strings that matched full pattern,
and $out[1] contains array of strings enclosed by tags.
</para>
</informalexample>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>PREG_SET_ORDER</term>
<listitem>
</screen>
<para>
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 role="php">
So, $out[0] contains array of strings that matched full pattern,
and $out[1] contains array of strings enclosed by tags.
</para>
</informalexample>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>PREG_SET_ORDER</term>
<listitem>
<para>
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 role="php">
<![CDATA[
<?php
preg_match_all("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=\"left\">this is a test</div>",
preg_match_all("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=\"left\">this is a test</div>",
$out, PREG_SET_ORDER);
echo $out[0][0] . ", " . $out[0][1] . "\n";
echo $out[1][0] . ", " . $out[1][1] . "\n";
?>
]]>
</programlisting>
<para>
This example will produce:
</para>
<screen role="html">
</programlisting>
<para>
This example will produce:
</para>
<screen role="html">
<![CDATA[
<b>example: </b>, example:
<b>example: </b>, example:
<div align="left">this is a test</div>, this is a test
]]>
</screen>
</informalexample>
</para>
<para>
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>
</listitem>
</varlistentry>
<varlistentry>
<term>PREG_OFFSET_CAPTURE</term>
<listitem>
<para>
If this flag is passed, for every occurring match the appendant string
offset will also be returned. Note that this changes the value of
<parameter>matches</parameter> in an array where every element is an
array consisting of the matched string at offset <literal>0</literal>
and its string offset into <parameter>subject</parameter> at offset
<literal>1</literal>.
This flag is available since PHP 4.3.0 .
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
If no order flag is given, <constant>PREG_PATTERN_ORDER</constant> is
assumed.
</para>
</screen>
</informalexample>
</para>
<para>
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>
</listitem>
</varlistentry>
<varlistentry>
<term>PREG_OFFSET_CAPTURE</term>
<listitem>
<para>
If this flag is passed, for every occurring match the appendant string
offset will also be returned. Note that this changes the value of
<parameter>matches</parameter> in an array where every element is an
array consisting of the matched string at offset <literal>0</literal>
and its string offset into <parameter>subject</parameter> at offset
<literal>1</literal>.
This flag is available since PHP 4.3.0 .
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
If no order flag is given, <constant>PREG_PATTERN_ORDER</constant> is
assumed.
</para>
<para>
Normally, the search starts from the beginning of the subject string. The
optional parameter <parameter>offset</parameter> can be used to specify
the alternate place from which to start the search.
The <parameter>offset</parameter> parameter is available since
PHP 4.3.3.
</para>
<para>
Normally, the search starts from the beginning of the subject string. The
optional parameter <parameter>offset</parameter> can be used to specify
the alternate place from which to start the search.
The <parameter>offset</parameter> parameter is available since
PHP 4.3.3.
</para>
<note>
<para>
Using <parameter>offset</parameter> is not equivalent to
passing <literal>substr($subject, $offset)</literal> to
<function>preg_match_all</function> in place of the subject string, because
<parameter>pattern</parameter> can contain assertions such as
<emphasis>^</emphasis>, <emphasis>$</emphasis> or
<emphasis>(?&lt;=x)</emphasis>. See <function>preg_match</function> for
examples.
</para>
</note>
<para>
Returns the number of full pattern matches (which might be zero),
or &false; if an error occurred.
</para>
<para>
<example>
<title>Getting all phone numbers out of some text.</title>
<programlisting role="php">
<note>
<para>
Using <parameter>offset</parameter> is not equivalent to
passing <literal>substr($subject, $offset)</literal> to
<function>preg_match_all</function> in place of the subject string, because
<parameter>pattern</parameter> can contain assertions such as
<emphasis>^</emphasis>, <emphasis>$</emphasis> or
<emphasis>(?&lt;=x)</emphasis>. See <function>preg_match</function> for
examples.
</para>
</note>
<para>
Returns the number of full pattern matches (which might be zero),
or &false; if an error occurred.
</para>
<para>
<example>
<title>Getting all phone numbers out of some text.</title>
<programlisting role="php">
<![CDATA[
<?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>
<para>
<example>
<title>Find matching HTML tags (greedy)</title>
<programlisting role="php">
</programlisting>
</example>
</para>
<para>
<example>
<title>Find matching HTML tags (greedy)</title>
<programlisting role="php">
<![CDATA[
<?php
// The \\2 is an example of backreferencing. This tells pcre that
// it must match the second set of parentheses in the regular expression
// itself, which would be the ([\w]+) in this case. The extra backslash is
// itself, which would be the ([\w]+) in this case. The extra backslash is
// required because the string is in double quotes.
$html = "<b>bold text</b><a href=howdy.html>click me</a>";
@ -188,11 +187,11 @@ foreach ($matches as $val) {
}
?>
]]>
</programlisting>
<para>
This example will produce:
</para>
<screen role="html">
</programlisting>
<para>
This example will produce:
</para>
<screen role="html">
<![CDATA[
matched: <b>bold text</b>
part 1: <b>
@ -204,16 +203,16 @@ part 1: <a href=howdy.html>
part 2: click me
part 3: </a>
]]>
</screen>
</example>
</para>
<simpara>
See also <function>preg_match</function>,
<function>preg_replace</function>,
and <function>preg_split</function>.
</simpara>
</refsect1>
</refentry>
</screen>
</example>
</para>
<simpara>
See also <function>preg_match</function>,
<function>preg_replace</function>,
and <function>preg_split</function>.
</simpara>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:

View file

@ -1,71 +1,70 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.20 $ -->
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 -->
<refentry id="function.preg-match">
<refnamediv>
<refname>preg_match</refname>
<refpurpose>Perform a regular expression match</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>preg_match</methodname>
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
<methodparam><type>string</type><parameter>subject</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter role="reference">matches</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>offset</parameter></methodparam>
</methodsynopsis>
<para>
Searches <parameter>subject</parameter> for a match to the regular
expression given in <parameter>pattern</parameter>.
</para>
<para>
If <parameter>matches</parameter> is provided, then it is filled with the
results of search. <varname>$matches[0]</varname> will contain the text
that matched the full pattern, <varname>$matches[1]</varname> will have
the text that matched the first captured parenthesized subpattern, and so
on.
</para>
<para>
<parameter>flags</parameter> can be the following flag:
<variablelist>
<varlistentry>
<term>PREG_OFFSET_CAPTURE</term>
<listitem>
<simpara>
If this flag is passed, for every occurring match the appendant string
offset will also be returned. Note that this changes the return value
in an array where every element is an array consisting of the matched
string at offset <literal>0</literal> and its string offset into
<parameter>subject</parameter> at offset <literal>1</literal>. This
flag is available since PHP 4.3.0 .
</simpara>
</listitem>
</varlistentry>
</variablelist>
The <parameter>flags</parameter> parameter is available since
PHP 4.3.0.
</para>
<!-- $Revision: 1.21 $ -->
<refentry id="function.preg-match">
<refnamediv>
<refname>preg_match</refname>
<refpurpose>Perform a regular expression match</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>preg_match</methodname>
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
<methodparam><type>string</type><parameter>subject</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter role="reference">matches</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>offset</parameter></methodparam>
</methodsynopsis>
<para>
Searches <parameter>subject</parameter> for a match to the regular
expression given in <parameter>pattern</parameter>.
</para>
<para>
If <parameter>matches</parameter> is provided, then it is filled with the
results of search. <varname>$matches[0]</varname> will contain the text
that matched the full pattern, <varname>$matches[1]</varname> will have
the text that matched the first captured parenthesized subpattern, and so
on.
</para>
<para>
<parameter>flags</parameter> can be the following flag:
<variablelist>
<varlistentry>
<term>PREG_OFFSET_CAPTURE</term>
<listitem>
<simpara>
If this flag is passed, for every occurring match the appendant string
offset will also be returned. Note that this changes the return value
in an array where every element is an array consisting of the matched
string at offset <literal>0</literal> and its string offset into
<parameter>subject</parameter> at offset <literal>1</literal>. This
flag is available since PHP 4.3.0 .
</simpara>
</listitem>
</varlistentry>
</variablelist>
The <parameter>flags</parameter> parameter is available since
PHP 4.3.0.
</para>
<para>
Normally, the search starts from the beginning of the subject string. The
optional parameter <parameter>offset</parameter> can be used to specify
the alternate place from which to start the search.
The <parameter>offset</parameter> parameter is available since
PHP 4.3.3.
</para>
<note>
<para>
Using <parameter>offset</parameter> is not equivalent to
passing <literal>substr($subject, $offset)</literal> to
<function>preg_match</function> in place of the subject string, because
<parameter>pattern</parameter> can contain assertions such as
<emphasis>^</emphasis>, <emphasis>$</emphasis> or
<emphasis>(?&lt;=x)</emphasis>. Compare:
</para>
<informalexample>
<programlisting role="php">
<para>
Normally, the search starts from the beginning of the subject string. The
optional parameter <parameter>offset</parameter> can be used to specify
the alternate place from which to start the search.
The <parameter>offset</parameter> parameter is available since
PHP 4.3.3.
</para>
<note>
<para>
Using <parameter>offset</parameter> is not equivalent to
passing <literal>substr($subject, $offset)</literal> to
<function>preg_match</function> in place of the subject string, because
<parameter>pattern</parameter> can contain assertions such as
<emphasis>^</emphasis>, <emphasis>$</emphasis> or
<emphasis>(?&lt;=x)</emphasis>. Compare:
</para>
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$subject = "abcdef";
@ -74,19 +73,19 @@ preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
print_r($matches);
?>
]]>
</programlisting>
&example.outputs;
<screen>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Array
(
)
]]>
</screen>
<para>
while this example
</para>
<programlisting role="php">
</screen>
<para>
while this example
</para>
<programlisting role="php">
<![CDATA[
<?php
$subject = "abcdef";
@ -95,11 +94,11 @@ preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
?>
]]>
</programlisting>
<para>
will produce
</para>
<screen>
</programlisting>
<para>
will produce
</para>
<screen>
<![CDATA[
Array
(
@ -111,31 +110,31 @@ Array
)
]]>
</screen>
</informalexample>
</note>
</screen>
</informalexample>
</note>
<para>
<function>preg_match</function> returns the number of times
<parameter>pattern</parameter> matches. That will be either 0 times
(no match) or 1 time because <function>preg_match</function> will stop
searching after the first match. <function>preg_match_all</function>
on the contrary will continue until it reaches the end of
<parameter>subject</parameter>.
<function>preg_match</function> returns &false; if an error occurred.
</para>
<tip>
<para>
Do not use <function>preg_match</function> if you only want to check if
one string is contained in another string. Use
<function>strpos</function> or <function>strstr</function> instead as
they will be faster.
</para>
</tip>
<para>
<example>
<title>Find the string of text "php"</title>
<programlisting role="php">
<para>
<function>preg_match</function> returns the number of times
<parameter>pattern</parameter> matches. That will be either 0 times
(no match) or 1 time because <function>preg_match</function> will stop
searching after the first match. <function>preg_match_all</function>
on the contrary will continue until it reaches the end of
<parameter>subject</parameter>.
<function>preg_match</function> returns &false; if an error occurred.
</para>
<tip>
<para>
Do not use <function>preg_match</function> if you only want to check if
one string is contained in another string. Use
<function>strpos</function> or <function>strstr</function> instead as
they will be faster.
</para>
</tip>
<para>
<example>
<title>Find the string of text "php"</title>
<programlisting role="php">
<![CDATA[
<?php
// The "i" after the pattern delimiter indicates a case-insensitive search
@ -146,13 +145,13 @@ if (preg_match("/php/i", "PHP is the web scripting language of choice.")) {
}
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Find the word "web"</title>
<programlisting role="php">
</programlisting>
</example>
</para>
<para>
<example>
<title>Find the word "web"</title>
<programlisting role="php">
<![CDATA[
<?php
/* The \b in the pattern indicates a word boundary, so only the distinct
@ -170,13 +169,13 @@ if (preg_match("/\bweb\b/i", "PHP is the website scripting language of choice.")
}
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Getting the domain name out of a URL</title>
<programlisting role="php">
</programlisting>
</example>
</para>
<para>
<example>
<title>Getting the domain name out of a URL</title>
<programlisting role="php">
<![CDATA[
<?php
// get host name from URL
@ -189,22 +188,22 @@ preg_match('/[^.]+\.[^.]+$/', $host, $matches);
echo "domain name is: {$matches[0]}\n";
?>
]]>
</programlisting>
&example.outputs;
<screen>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
domain name is: php.net
]]>
</screen>
</example>
</para>
<para>
See also <function>preg_match_all</function>,
<function>preg_replace</function>, and
<function>preg_split</function>.
</para>
</refsect1>
</refentry>
</screen>
</example>
</para>
<para>
See also <function>preg_match_all</function>,
<function>preg_replace</function>, and
<function>preg_split</function>.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:

View file

@ -1,38 +1,37 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 -->
<refentry id="function.preg-quote">
<refnamediv>
<refname>preg_quote</refname>
<refpurpose>Quote regular expression characters</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>preg_quote</methodname>
<methodparam><type>string</type><parameter>str</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>delimiter</parameter></methodparam>
</methodsynopsis>
<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>
<para>
If the optional <parameter>delimiter</parameter> is specified, it
will also be escaped. This is useful for escaping the delimiter
that is required by the PCRE functions. The / is the most commonly
used delimiter.</para>
<para>
The special regular expression characters are:
<literal>. \ + * ? [ ^ ] $ ( ) { } = ! &lt; &gt; | :</literal>
</para>
<para>
<example>
<title><function>preg_quote</function> example</title>
<programlisting role="php">
<!-- $Revision: 1.9 $ -->
<refentry id="function.preg-quote">
<refnamediv>
<refname>preg_quote</refname>
<refpurpose>Quote regular expression characters</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>preg_quote</methodname>
<methodparam><type>string</type><parameter>str</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>delimiter</parameter></methodparam>
</methodsynopsis>
<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>
<para>
If the optional <parameter>delimiter</parameter> is specified, it
will also be escaped. This is useful for escaping the delimiter
that is required by the PCRE functions. The / is the most commonly
used delimiter.</para>
<para>
The special regular expression characters are:
<literal>. \ + * ? [ ^ ] $ ( ) { } = ! &lt; &gt; | :</literal>
</para>
<para>
<example>
<title><function>preg_quote</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$keywords = '$40 for a g3/400';
@ -40,13 +39,13 @@ $keywords = preg_quote($keywords, '/');
echo $keywords; // returns \$40 for a g3\/400
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Italicizing a word within some text</title>
<programlisting role="php">
</programlisting>
</example>
</para>
<para>
<example>
<title>Italicizing a word within some text</title>
<programlisting role="php">
<![CDATA[
<?php
// In this example, preg_quote($word) is used to keep the
@ -60,14 +59,14 @@ $textbody = preg_replace ("/" . preg_quote($word) . "/",
$textbody);
?>
]]>
</programlisting>
</example>
</para>
</programlisting>
</example>
</para>
&note.bin-safe;
&note.bin-safe;
</refsect1>
</refentry>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.13 $ -->
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.47 -->
<!-- $Revision: 1.14 $ -->
<refentry id="function.preg-replace-callback">
<refnamediv>
<refname>preg_replace_callback</refname>
@ -35,7 +34,7 @@
$text = "April fools day is 04/01/2002\n";
$text.= "Last christmas was 12/24/2001\n";
// the callback function
function next_year($matches)
function next_year($matches)
{
// as usual: $matches[0] is the complete match
// $matches[1] the match for the first subpattern
@ -96,11 +95,11 @@ fclose($fp);
<programlisting role='php'>
<![CDATA[
<?php
$input = "plain [indent] deep [indent] deeper [/indent] deep [/indent] plain";
$input = "plain [indent] deep [indent] deeper [/indent] deep [/indent] plain";
function parseTagsRecursive($input)
function parseTagsRecursive($input)
{
$regex = '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#';
if (is_array($input)) {

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.19 $ -->
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 -->
<!-- $Revision: 1.20 $ -->
<refentry id="function.preg-replace">
<refnamediv>
<refname>preg_replace</refname>

View file

@ -1,84 +1,83 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.11 $ -->
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 -->
<refentry id="function.preg-split">
<refnamediv>
<refname>preg_split</refname>
<refpurpose>Split string by a regular expression</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>array</type><methodname>preg_split</methodname>
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
<methodparam><type>string</type><parameter>subject</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>limit</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter></methodparam>
</methodsynopsis>
<!-- $Revision: 1.12 $ -->
<refentry id="function.preg-split">
<refnamediv>
<refname>preg_split</refname>
<refpurpose>Split string by a regular expression</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>array</type><methodname>preg_split</methodname>
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
<methodparam><type>string</type><parameter>subject</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>limit</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter></methodparam>
</methodsynopsis>
<para>
Returns an array containing substrings of
<parameter>subject</parameter> split along boundaries matched by
<parameter>pattern</parameter>.
</para>
<para>
If <parameter>limit</parameter> is specified, then only substrings up to
<parameter>limit</parameter> are returned, and if
<parameter>limit</parameter> is -1, it actually means "no limit", which is
useful for specifying the <parameter>flags</parameter>.
</para>
<para>
<parameter>flags</parameter> can be any combination of the following flags
(combined with bitwise | operator):
<variablelist>
<varlistentry>
<term><constant>PREG_SPLIT_NO_EMPTY</constant></term>
<listitem>
<simpara>
If this flag is set, only non-empty pieces will be returned by
<function>preg_split</function>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>PREG_SPLIT_DELIM_CAPTURE</constant></term>
<listitem>
<simpara>
If this flag is set, parenthesized expression in the delimiter pattern
will be captured and returned as well. This flag was added for 4.0.5.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>PREG_SPLIT_OFFSET_CAPTURE</constant></term>
<listitem>
<para>
If this flag is set, for every occurring match the appendant string
offset will also be returned. Note that this changes the return
value in an array where every element is an array consisting of the
matched string at offset <literal>0</literal> and its string offset
into <parameter>subject</parameter> at offset <literal>1</literal>.
This flag is available since PHP 4.3.0 .
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<tip>
<para>
Returns an array containing substrings of
<parameter>subject</parameter> split along boundaries matched by
<parameter>pattern</parameter>.
If you don't need the power of regular expressions, you can choose
faster (albeit simpler) alternatives like <function>explode</function>
or <function>str_split</function>.
</para>
</tip>
<para>
If <parameter>limit</parameter> is specified, then only substrings up to
<parameter>limit</parameter> are returned, and if
<parameter>limit</parameter> is -1, it actually means "no limit", which is
useful for specifying the <parameter>flags</parameter>.
</para>
<para>
<parameter>flags</parameter> can be any combination of the following flags
(combined with bitwise | operator):
<variablelist>
<varlistentry>
<term><constant>PREG_SPLIT_NO_EMPTY</constant></term>
<listitem>
<simpara>
If this flag is set, only non-empty pieces will be returned by
<function>preg_split</function>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>PREG_SPLIT_DELIM_CAPTURE</constant></term>
<listitem>
<simpara>
If this flag is set, parenthesized expression in the delimiter pattern
will be captured and returned as well. This flag was added for 4.0.5.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>PREG_SPLIT_OFFSET_CAPTURE</constant></term>
<listitem>
<para>
If this flag is set, for every occurring match the appendant string
offset will also be returned. Note that this changes the return
value in an array where every element is an array consisting of the
matched string at offset <literal>0</literal> and its string offset
into <parameter>subject</parameter> at offset <literal>1</literal>.
This flag is available since PHP 4.3.0 .
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<tip>
<para>
If you don't need the power of regular expressions, you can choose
faster (albeit simpler) alternatives like <function>explode</function>
or <function>str_split</function>.
</para>
</tip>
<para>
<example>
<title><function>preg_split</function> example : Get the parts of a search string</title>
<programlisting role="php">
<para>
<example>
<title><function>preg_split</function> example : Get the parts of a search string</title>
<programlisting role="php">
<![CDATA[
<?php
// split the phrase by any number of commas or space characters,
@ -86,13 +85,13 @@
$keywords = preg_split("/[\s,]+/", "hypertext language, programming");
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Splitting a string into component characters</title>
<programlisting role="php">
</programlisting>
</example>
</para>
<para>
<example>
<title>Splitting a string into component characters</title>
<programlisting role="php">
<![CDATA[
<?php
$str = 'string';
@ -100,13 +99,13 @@ $chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
print_r($chars);
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Splitting a string into matches and their offsets</title>
<programlisting role="php">
</programlisting>
</example>
</para>
<para>
<example>
<title>Splitting a string into matches and their offsets</title>
<programlisting role="php">
<![CDATA[
<?php
$str = 'hypertext language programming';
@ -114,11 +113,11 @@ $chars = preg_split('/ /', $str, -1, PREG_SPLIT_OFFSET_CAPTURE);
print_r($chars);
?>
]]>
</programlisting>
<para>
will yield:
</para>
<screen>
</programlisting>
<para>
will yield:
</para>
<screen>
<![CDATA[
Array
(
@ -142,22 +141,22 @@ Array
)
]]>
</screen>
</example>
</para>
<note>
<para>
Parameter <parameter>flags</parameter> was added in PHP 4 Beta 3.
</para>
</note>
<para>
See also <function>spliti</function>, <function>split</function>,
<function>implode</function>, <function>preg_match</function>,
<function>preg_match_all</function>, and
<function>preg_replace</function>.
</para>
</refsect1>
</refentry>
</screen>
</example>
</para>
<note>
<para>
Parameter <parameter>flags</parameter> was added in PHP 4 Beta 3.
</para>
</note>
<para>
See also <function>spliti</function>, <function>split</function>,
<function>implode</function>, <function>preg_match</function>,
<function>preg_match_all</function>, and
<function>preg_replace</function>.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables: