note 93936 added to function.preg-match-all
| From: | Jason at osu1 dot php dot net | Date: | Wed, 07 Oct 2009 14:59:02 +0000 |
| Subject: | note 93936 added to function.preg-match-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161472@lists.php.net to get a copy of this message | ||
"Example #3 Using named subpattern" above does not work, at least in PHP 5. Named tags
should contain a capital P after the question mark and before the less than sign.
This:
?<name>
Should look like this:
?P<name>
So, the correct code for PHP5 for "Example #3 Using named subpattern", should look like
this:
<?php
$str = <<<FOO
a: 1
b: 2
c: 3
FOO;
preg_match_all('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches);
print_r($matches);
?>
This will prevent an error similar to:
"Warning: preg_match_all() [function.preg-match-all]: Compilation failed: unrecognized
character after (?< at offset 3"
----
Server IP: 64.71.164.2
Probable Submitter: 63.149.27.10
----
Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php
Edit -- https://master.php.net/note/edit/93936
Del: integrated -- https://master.php.net/note/delete/93936/integrated
Del: useless -- https://master.php.net/note/delete/93936/useless
Del: bad code -- https://master.php.net/note/delete/93936/bad+code
Del: spam -- https://master.php.net/note/delete/93936/spam
Del: non-english -- https://master.php.net/note/delete/93936/non-english
Del: in docs -- https://master.php.net/note/delete/93936/in+docs
Del: other reasons-- https://master.php.net/note/delete/93936
Reject -- https://master.php.net/note/reject/93936
Search -- https://master.php.net/manage/user-notes.php