preg_match_all 函数:
int preg_match_all ( string pattern, string subject, array matches [, int flags] )执行一个全局正则表达式匹配
在 subje*本5文来源gaodai$ma#com搞$$代**码)网@搞代码gaodaimact 中搜索所有与 pattern 给出的正则表达式匹配的内容并将结果以 flags 指定的顺序放到 matches 中。
搜索到第一个匹配项之后,接下来的搜索从上一个匹配项末尾开始。
flags 可以是下列标记的组合(注意把 PREG_PATTERN_ORDER 和 PREG_SET_ORDER 合起来用没有意义):
PREG_PATTERN_ORDER 对结果排序使 $matches[0] 为全部模式匹配的数组,$matches[1] 为第一个括号中的子模式所匹配的字符串组成的数组,以此类推!
例子:
<?php<BR>$con = file_get_contents("http://www.php.net/news/jb-1.html");<BR>$pattern="//";<BR>preg_match_all($pattern,$con,$match);<BR>print_r($match);<BR>?> <BR>
结果:
Array<BR>(<BR> [0] => Array<BR> (<BR> [0] => <BR> [1] => <BR> [2] => <BR> )<BR> [1] => Array<BR> (<BR> [0] => http://www.php.net/usr/themes/dddefault/images/logo.png<BR> [1] => http://www.php.net/usr/uploads/2012/09/531656480.jpg<BR> [2] => http://www.php.net/usr/uploads/2012/09/2647136297.jpg<BR> )<BR>)<BR>