Use preg_match_all in php to match the image in the article. Preg_match_all function: intpreg_match_all (stringpattern, stringsubject, arraymatches [, intflags]) execute a global regular expression match to search all functions in subject that match pa preg_match_all:
Int preg_match_all (string pattern, string subject, array matches [, int flags]) executes a global regular expression match.
Search all the content that matches the regular expression given by pattern in the subject and put the result in the matches in the order specified by flags.
After the first match is found, the next search starts from the end of the previous match.
Flags can be a combination of the following tags (note that it is meaningless to combine PREG_PATTERN_ORDER and PREG_SET_ORDER ):
PREG_PATTERN_ORDER sorts the results so that $ matches [0] is an array of all pattern matching, $ matches [1] is an array consisting of strings matching the child pattern in the first bracket, and so on!
Example:
The code is as follows:
$ Con = file_get_contents ("http://www.jb51.net/news/jb-1.html ");
$ Pattern = "/<[img | IMG]. *? Src = [\ '| \ "] (. *? (? : [\. Gif | \. jpg | \. png]) [\ '| \ "]. *? [\/]?> /";
Preg_match_all ($ pattern, $ con, $ match );
Print_r ($ match );
?>
Result:
The code is as follows:
Array
(
[0] => Array
(
[0] =>
[1] =>
[2] =>
)
[1] => Array
(
Http://www.jb51.net/usr/themes/dddefault/images/logo.png
Http://www.jb51.net/usr/uploads/2012/09/531656480.jpg
Http://www.jb51.net/usr/uploads/2012/09/2647136297.jpg
)
)
Http://www.bkjia.com/PHPjc/326445.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326445.htmlTechArticlepreg_match_all function: int preg_match_all (string pattern, string subject, array matches [, int flags]) execute a global regular expression matching all match pa in subject...