preg_match_all will fill the third argument with the match results.
for instance, this command will return all the span tags in an html document and put them into the array $match_results. $match_results will be a two-dimensional array with the first dimension corresponding to the () groupings in your pattern and the second dimension corresponding to which search it corresponds to.
$num_matches = preg_match_all("#(<span)([^>]*)(>)#is", $string_to_search, $match_results);
echo $num_matches . " MATCHES FOUND<br>\n";
echo "<hr>COMPLETE MATCHES<br>";
foreach($match_results[0] as $key=>$match0) {
echo htmlspecialchars($match0) . "<br>";
}
// all span tags--boring
echo "<hr>MATCHES corresponding to \\1<br>";
foreach($match_results[1] as $key=>$match1) {
echo htmlspecialchars($match1) . "<br>";
}
// attributes--interesting??
echo "<hr>MATCHES corresponding to \\2<br>";
foreach($match_results[2] as $key=>$match2) {
echo htmlspecialchars($match2) . "<br>";
}
NOTE: i have not debugged this code. it may or may not work.
for more information, check here:
http://us3.php.net/manual/en/function.preg-match-all.php