Preg_match_all function:
int Preg_match_all (string pattern, string subject, array matches [, int flags]) performs a global regular expression match
Searches in subject for all content that matches the regular expression given by the pattern and places the result in matches in the order specified by flags.
After the first match is searched, the next search starts at the end of the previous match.
Flags can be a combination of the following tags (note that it makes no sense to combine Preg_pattern_order and Preg_set_order):
Preg_pattern_order The result sort so that $matches [0] is an array of all pattern matches, $matches [1] is an array of strings that match the sub-patterns in the first parenthesis, and so on!
Example:
Copy the Code code as follows:
$con = file_get_contents ("http://www.php.net/news/jb-1.html");
$pattern = "/<[img| Img].*?src=[\ ' |\ "] (. *? (?: [\.gif|\.jpg|\.png])) [\ ' |\ '].*? [\/]?>/];
Preg_match_all ($pattern, $con, $match);
Print_r ($match);
?>
Results:
Copy the Code code as follows:
Array
(
[0] = = Array
(
[0] = =
[1] = =
[2] = =
)
[1] = = Array
(
[0] = Http://www.php.net/usr/themes/dddefault/images/logo.png
[1] = Http://www.php.net/usr/uploads/2012/09/531656480.jpg
[2] = Http://www.php.net/usr/uploads/2012/09/2647136297.jpg
)
)