preg_match prob
Posted: Tue Dec 30, 2003 2:58 pm
I'm having an odd problem with some regex code I'm working on, this is almost an exact copy from another program I wrote that works perfectly.
However this piece of code will only display the first expression results, no matter which way round you place them, it will only display the first set of results.
Should I be resetting anything in between them? The count output from the first section is always correct, but it's always zero on the second and any other sections after that. I haven't done a great deal with regex before so maybe I'm missing something important here.
It's probably something simple but any help would be appreciated as it's driving me crazy now.
However this piece of code will only display the first expression results, no matter which way round you place them, it will only display the first set of results.
Should I be resetting anything in between them? The count output from the first section is always correct, but it's always zero on the second and any other sections after that. I haven't done a great deal with regex before so maybe I'm missing something important here.
It's probably something simple but any help would be appreciated as it's driving me crazy now.
Code: Select all
$date = '<([A-Z]{1}[a-z]{2}) ([0-9]{1,2}), ([0-1]?[0-9]|[2][0-3]):([0-5][0-9]):([0-5][0-9])> ';
$skill_hit = 'You hit the ([a-zA-Z ]+) with ([a-zA-Z ]+) for ([0-9\,]+) points of damage\.';
$skill_evade = 'You try to use ([a-zA-Z ]+) on the ([a-zA-Z ]+), but it evades\.';
print ('<b>-------- SKILL HITS --------------------------------------</b><br>');
preg_match_all('/'.$date.$skill_hit.'/', $content, $matches);
print ('count = '.count($matches[0]).'<br>');
for ($i=0; $i< count($matches[0]); $i++)
{
$date = $matches[1][$i].' '.$matches[2][$i];
$time = $matches[3][$i].':'.$matches[4][$i].':'.$matches[5][$i];
$mob = $matches[6][$i];
$skill = $matches[7][$i];
$dmg = $matches[8][$i];
print ('<b>'.$date.', '.$time.' -</b> You hit the '.$mob.' with '.$skill.' for '.$dmg.' points of damage.<br>');
}
print ('<b>-------- SKILL EVADES --------------------------------------</b><br>');
preg_match_all('/'.$date.$skill_evade.'/', $content, $matches);
print ('count = '.count($matches[0]).'<br>');
for ($i=0; $i< count($matches[0]); $i++)
{
$date = $matches[1][$i].' '.$matches[2][$i];
$time = $matches[3][$i].':'.$matches[4][$i].':'.$matches[5][$i];
$skill = $matches[6][$i];
$mob = $matches[7][$i];
print ('<b>'.$date.', '.$time.' -</b> You tried to use '.$skill.' on the '.$mob.', but it evaded.<br>');
}