Page 1 of 1

nth occurrence of a pattern

Posted: Thu Jul 07, 2005 9:59 am
by anjanesh

Code: Select all

 
$xml = "
<starttag>
<starttag>...</endtag>
<starttag>...</endtag>
<starttag>...</endtag>
<starttag>...</endtag>
</endtag>
";
$pattern = "/<starttag>(.*?)[<\/endtag>]/is";
preg_match($pattern,$xml,$matches);
print_r($matches);
 
What do I have to change in the pattern to get the 5th occurrence of <endtag> ?

Thanks