#49395 [NEW]: typo in the code
| From: | a1call at hotmail dot com | Date: | Thu, 27 Aug 2009 22:44:24 +0000 |
| Subject: | #49395 [NEW]: typo in the code | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-2678@lists.php.net to get a copy of this message | ||
From: a1call at hotmail dot com
Operating system:
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: typo in the code
Description:
------------
The example code on page:
http://ca3.php.net/preg_match_all
is skipping a variable and does not produce te reported result.
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";
}
?>
--
Edit bug report at http://bugs.php.net/?id=49395&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49395&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49395&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49395&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=49395&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49395&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=49395&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=49395&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=49395&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=49395&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=49395&r=support
Expected behavior: http://bugs.php.net/fix.php?id=49395&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=49395&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=49395&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=49395&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49395&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49395&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=49395&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=49395&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=49395&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=49395&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=49395&r=mysqlcfg