|
Posted by Damo on 03/02/07 17:16
I'm slowly getting the hang of regex's, Instead ive starting a new
thread i thought id ask here. I have this regex:
$regexp = "%<li><a href=\"(.+?)\">.+[^>]+>([^<]+)</a>.+<span class=
\"date\">(.+?)</span>.+<div class=\"abstract\">(.+?)</div>%s";
It matches a the URL of a link, the text of a link, a date and the
abstract of a story.
If I use preg_match_all and theres multiple matches to the pattern in
a html string, it inly stores the last one in $matches
this is how i'm printing them:
preg_match_all($regexp,$document,$matches);
$numMatches = count($matches[1]);
for ($i=0;$i <= $numMatches-1; $i++)
{
echo $matches[1][$i]."<br>";
echo $matches[2][$i]."<br>";
echo $matches[3][$i]."<br>";
echo $matches[4][$i]."<br>";
}
I have no idea why its skipping the earlier matches.
Thanks
Navigation:
[Reply to this message]
|