#48806 [Opn->Csd]: Typo on preg_match_all manual page
| From: | rasmus@php.net | Date: | Sun, 19 Jul 2009 23:59:59 +0000 |
| Subject: | #48806 [Opn->Csd]: Typo on preg_match_all manual page | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-2513@lists.php.net to get a copy of this message | ||
ID: 48806
Updated by: rasmus@php.net
Reported By: alaattin at gmail dot com
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: Debian Linux (Lenny)
PHP Version: Irrelevant
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Previous Comments:
------------------------------------------------------------------------
[2009-07-19 23:58:44] svn@php.net
Automatic comment from SVN on behalf of rasmus
Log: Fixed bug #48806
Revision: http://svn.php.net/viewvc?view=revision&revision=284401
------------------------------------------------------------------------
[2009-07-05 16:16:59] alaattin at gmail dot com
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 this bug report at http://bugs.php.net/?id=48806&edit=1