#48806 [NEW]: Typo on preg_match_all manual page
| From: | alaattin at gmail dot com | Date: | Sun, 05 Jul 2009 16:16:59 +0000 |
| Subject: | #48806 [NEW]: Typo on preg_match_all manual page | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-2451@lists.php.net to get a copy of this message | ||
From: alaattin at gmail dot com
Operating system: Debian Linux (Lenny)
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: Typo on preg_match_all manual page
Description:
------------
The code supplied on
http://tr.php.net/manual/en/function.preg-match-all.php
in Example 2 is
erronous,
If the document contains more than one occurences of a tag, than it
fails:
$html = '<h1>Heading Largest First</h1><h2>Heading Larger
First</h2><a
href=howdy.html>click me</a><h1>Heading Largest Second</h1>Some
text<h3>Heading Normal</h3>';
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";
}
?>
The ouput is:
matched: <h1>Heading Largest First</h1><h2>Heading Larger First</h2><a
href=howdy.html>click me</a><h1>Heading Largest Second</h1>
part 1: <h1>
part 2: Heading Largest First</h1><h2>Heading Larger First</h2><a
href=howdy.html>click me</a><h1>Heading Largest Second
part 3: </h1>
matched: <h3>Heading Normal</h3>
part 1: <h3>
part 2: Heading Normal
part 3: </h3>
The reqular expression is missing a question mark, the corrected snippet
should be:
$html = '<h1>Heading Largest First</h1><h2>Heading Larger
First</h2><a
href=howdy.html>click me</a><h1>Heading Largest Second</h1>Some
text<h3>Heading Normal</h3>';
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";
}
?>
Then the output will be:
matched: <h1>Heading Largest First</h1>
part 1: <h1>
part 2: Heading Largest First
part 3: </h1>
matched: <h2>Heading Larger First</h2>
part 1: <h2>
part 2: Heading Larger First
part 3: </h2>
matched: <a href=howdy.html>click me</a>
part 1: <a href=howdy.html>
part 2: click me
part 3: </a>
matched: <h1>Heading Largest Second</h1>
part 1: <h1>
part 2: Heading Largest Second
part 3: </h1>
matched: <h3>Heading Normal</h3>
part 1: <h3>
part 2: Heading Normal
part 3: </h3>
--
Edit bug report at http://bugs.php.net/?id=48806&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48806&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48806&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48806&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=48806&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48806&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=48806&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=48806&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=48806&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=48806&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=48806&r=support
Expected behavior: http://bugs.php.net/fix.php?id=48806&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=48806&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=48806&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=48806&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48806&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48806&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=48806&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=48806&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=48806&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=48806&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=48806&r=mysqlcfg