Re: regexp appears to be faulty (DONT actually think so)
| From: | Henry Grech-Cini | Date: | Tue, 24 Feb 2004 13:19:36 +0000 |
| Subject: | Re: regexp appears to be faulty (DONT actually think so) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-178683@lists.php.net to get a copy of this message | ||
Hi All,
I don't actually think regexp is fault. But if anyone could explain this or
give me some example code that will extract the attributes and data between
a "fieldset" tag pair I would be appreciated.
Henry
"Henry Grech-Cini" <henry@teacake.force9.co.uk> wrote in message
news:20040224124017.75521.qmail@pb1.pair.com...
> 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?