note 52537 deleted from function.preg-match-all by betz
| From: | betz@php.net | Date: | Thu, 05 May 2005 07:54:57 +0000 |
| Subject: | note 52537 deleted from function.preg-match-all by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-88952@lists.php.net to get a copy of this message | ||
Note Submitter: djmaze (AT) dragonflycms
Reason: useless
----
As seen in example 2:
preg_match_all("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/s", $html, $matches);
Only works on tags with content like <b>content</b> but doesn't list
"empty" tags like <b></b>
To get around this you could use:
preg_match_all("/(<([\w]+)[^>]*>)(.*?)(<\/\\2>)/s", $html, $matches);
Which works on tags with no content
However this does give issues with nested tags like:
<?php
$html = "<table><tr><td>
<table><tr><td><b>bold text</b></td></tr></table>
</td></tr></table>";
preg_match_all("/(<([\w]+)[^>]*>)(.*?)(<\/\\2>)/s", $html, $matches);
for ($i=0; $i< count($matches[0]); $i++) {
echo "matched: " . $matches[0][$i] . "\n";
echo "part 1: " . $matches[1][$i] . "\n";
echo "part 2: " . $matches[3][$i] . "\n";
echo "part 3: " . $matches[4][$i] . "\n\n";
}
?>
matched: <table><tr><td>
<table><tr><td><b>bold text</b></td></tr></table>
part 1: <table>
part 2: <tr><td>
<table><tr><td><b>bold text</b></td></tr>
part 3: </table>
I didn't find a correct solution as of yet, maybe someone else will.