note 93193 added to function.preg-match-all
| From: | a1call at hotmail dot com | Date: | Thu, 27 Aug 2009 21:16:11 +0000 |
| Subject: | note 93193 added to function.preg-match-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159949@lists.php.net to get a copy of this message | ||
the example given is skipping an array entry. Should be:
<?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
// required because the string is in double quotes.
$html = "<b>bold text</b><a href=howdy.html>click me</a>";
preg_match_all("/(<([\w]+)[^>]*>)(.*?)(<\/\\2>)/", $html, $matches,
PREG_SET_ORDER);
foreach ($matches as $val) {
echo "matched: " . $val[0] . "\n";
echo "part 1: " . $val[1] . "\n";
echo "part 2: " . $val[2] . "\n";
echo "part 3: " . $val[3] . "\n\n";
}
?>
instead of:
<?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
// required because the string is in double quotes.
$html = "<b>bold text</b><a href=howdy.html>click me</a>";
preg_match_all("/(<([\w]+)[^>]*>)(.*?)(<\/\\2>)/", $html, $matches,
PREG_SET_ORDER);
foreach ($matches as $val) {
echo "matched: " . $val[0] . "\n";
echo "part 1: " . $val[1] . "\n";
echo "part 2: " . $val[3] . "\n";
echo "part 3: " . $val[4] . "\n\n";
}
?>
----
Server IP: 216.235.13.26
Probable Submitter: 64.228.81.81
----
Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php
Edit -- https://master.php.net/note/edit/93193
Del: integrated -- https://master.php.net/note/delete/93193/integrated
Del: useless -- https://master.php.net/note/delete/93193/useless
Del: bad code -- https://master.php.net/note/delete/93193/bad+code
Del: spam -- https://master.php.net/note/delete/93193/spam
Del: non-english -- https://master.php.net/note/delete/93193/non-english
Del: in docs -- https://master.php.net/note/delete/93193/in+docs
Del: other reasons-- https://master.php.net/note/delete/93193
Reject -- https://master.php.net/note/reject/93193
Search -- https://master.php.net/manage/user-notes.php