preg_match_all
Syntax
int preg_match_all ( string pattern, string subject, array &matches [, int flags [, int offset] ] )
Popis
Príkaz jazyka PHP
Searches subject for all matches to the regular expression given in pattern and puts them in matches in the order specified by flags.
After the first match is found, the subsequent searches are continued on from end of the last match.
flags can be a combination of the following flags (note that it doesn't make sense to use PREG_PATTERN_ORDER together with PREG_SET_ORDER):
PREG_PATTERN_ORDER
Orders results so that $matches[0] is an array of full pattern matches, $matches[1] is an array of strings matched by the first parenthesized subpattern, and so on.
Príklad
<?php
preg_match_all("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=left>this is a test</div>",
$out, PREG_PATTERN_ORDER);
echo $out[0][0] . ", " . $out[0][1] . "\n";
echo $out[1][0] . ", " . $out[1][1] . "\n";
/*This example will produce:
<b>example: </b>, <div align=left>this is a test</div>
example: , this is a test
*/
?>
preg_match_all("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=left>this is a test</div>",
$out, PREG_PATTERN_ORDER);
echo $out[0][0] . ", " . $out[0][1] . "\n";
echo $out[1][0] . ", " . $out[1][1] . "\n";
/*This example will produce:
<b>example: </b>, <div align=left>this is a test</div>
example: , this is a test
*/
?>
Pozri aj
preg_match, preg_replace a preg_split