regexp appears to be faulty!?
| From: | Henry Grech-Cini | Date: | Tue, 24 Feb 2004 12:40:22 +0000 |
| Subject: | regexp appears to be faulty!? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-178681@lists.php.net to get a copy of this message | ||
Hi All,
function extractFieldsets($subject)
{
$regexp="/<fieldset([^>]*)>[^(<\/fieldset>)]*/i";
$replacement;
$matches=array();
preg_match_all($regexp, $subject, $matches);
return ($matches);
}
$result=extractFieldsets('test<fieldset attribute="hello">content of
hello</fieldset><em>blah</em><fieldset
attribute="goodbye">goodbye</fieldset>');
echo "<br/>";
foreach($result as $key=>$string)
{
echo "(".$key.")="."<br/>";
foreach($string as $subkey=>$subres)
echo "
(".$subkey.")=[".htmlspecialchars($subres)."]<br/>";
echo "<br/>";
}
And it produced;
(0)=
(0)=[<fieldset attribute="hello">con]
(1)=[<fieldset attribute="goodbye">goo]
(1)=
(0)=[ attribute="hello"]
(1)=[ attribute="goodbye"]
Why did it get three letters after the end of the "fieldset" tag????
"con" and "goo".
Any pointers?