Add example (using named subpattern)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@251266 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Felipe Pena 2008-01-24 17:04:27 +00:00
parent f942b094a6
commit e0c25b85eb
2 changed files with 98 additions and 2 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.25 $ -->
<!-- $Revision: 1.26 $ -->
<refentry xml:id="function.preg-match-all" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>preg_match_all</refname>
@ -265,6 +265,71 @@ matched: <a href=howdy.html>click me</a>
part 1: <a href=howdy.html>
part 2: click me
part 3: </a>
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Using named subpattern</title>
<programlisting role="php">
<![CDATA[
<?php
$str = <<<FOO
a: 1
b: 2
c: 3
FOO;
preg_match_all('/(?<name>\w+): (?<digit>\d+)/', $str, $matches);
print_r($matches);
?>
]]>
</programlisting>
&example.outputs;
<screen role="html">
<![CDATA[
Array
(
[0] => Array
(
[0] => a: 1
[1] => b: 2
[2] => c: 3
)
[name] => Array
(
[0] => a
[1] => b
[2] => c
)
[1] => Array
(
[0] => a
[1] => b
[2] => c
)
[digit] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[2] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
)
]]>
</screen>
</example>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.26 $ -->
<!-- $Revision: 1.27 $ -->
<refentry xml:id="function.preg-match" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>preg_match</refname>
@ -262,6 +262,37 @@ echo "domain name is: {$matches[0]}\n";
<screen>
<![CDATA[
domain name is: php.net
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Using named subpattern</title>
<programlisting role="php">
<![CDATA[
<?php
$str = 'foobar: 2008';
preg_match('/(?<name>\w+): (?<digit>\d+)/', $str, $matches);
print_r($matches);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Array
(
[0] => foobar: 2008
[name] => foobar
[1] => foobar
[digit] => 2008
[2] => 2008
)
]]>
</screen>
</example>