mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Emphasize the use of ?P<> for named sub-patterns instead of the backwards incompatible ?<>. Fixes bug #50306 - refs bug #46904
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@292248 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
c83a8768d8
commit
740a7698af
2 changed files with 21 additions and 7 deletions
|
@ -162,7 +162,7 @@ echo $out[1][0] . ", " . $out[1][1] . "\n";
|
|||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Using <parameter>offset</parameter> is not equivalent to passing
|
||||
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
|
||||
|
@ -197,6 +197,16 @@ echo $out[1][0] . ", " . $out[1][1] . "\n";
|
|||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>5.2.2</entry>
|
||||
<entry>
|
||||
Named subpatterns now accept the
|
||||
syntax <literal>(?<name>)</literal>
|
||||
and <literal>(?'name')</literal> as well
|
||||
as <literal>(?P<name>)</literal>. Previous versions
|
||||
accepted only <literal>(?P<name>)</literal>.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>4.3.3</entry>
|
||||
<entry>
|
||||
|
@ -285,7 +295,11 @@ b: 2
|
|||
c: 3
|
||||
FOO;
|
||||
|
||||
preg_match_all('/(?<name>\w+): (?<digit>\d+)/', $str, $matches);
|
||||
preg_match_all('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches);
|
||||
|
||||
/* This also works in PHP 5.2.2 (PCRE 7.0) and later, however
|
||||
* the above form is recommended for backwards compatibility */
|
||||
// preg_match_all('/(?<name>\w+): (?<digit>\d+)/', $str, $matches);
|
||||
|
||||
print_r($matches);
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Using <parameter>offset</parameter> is not equivalent to passing
|
||||
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
|
||||
|
@ -286,11 +286,11 @@ domain name is: php.net
|
|||
|
||||
$str = 'foobar: 2008';
|
||||
|
||||
// Works in PHP 5.2.2 and later.
|
||||
preg_match('/(?<name>\w+): (?<digit>\d+)/', $str, $matches);
|
||||
preg_match('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches);
|
||||
|
||||
// Before PHP 5.2.2, use this:
|
||||
// preg_match('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches);
|
||||
/* This also works in PHP 5.2.2 (PCRE 7.0) and later, however
|
||||
* the above form is recommended for backwards compatibility */
|
||||
// preg_match('/(?<name>\w+): (?<digit>\d+)/', $str, $matches);
|
||||
|
||||
print_r($matches);
|
||||
|
||||
|
|
Loading…
Reference in a new issue