PHP uses Preg_match_all to match the pictures in the article,
Sometimes we need to use PHP to get a picture of the page and save it, here we can use Preg_match_all to match the image address, the need for code farmers can refer to the next
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:
PHP$confile_get_contents("http://www.xxx.com/news/jb-1.html"); $pattern= "/<[img| Img].*?src=[\ ' |\ "] (. *? (?: [\.gif|\.jpg|\.png])) [\ ' |\ '].*? [\/]?>/]; Preg_match_all ($pattern,$con,$match); Print_r ($match);
Results:
Array ( [[[1] = [ 2] = = ) Array ( [0] + = http://Www.xxx.com/usr/themes/dddefault/images/logo.png [1] = = http://www.xxx.com/usr/uploads/2012/09/531656480.jpg [2] = = http://www.xxx.com/usr/uploads/2012/09/2647136297.jpg ))
Original address: http://www.manongjc.com/article/708.html
Related reading:
PHP Preg_match_all combined with str_replace to replace all img in content
Analysis of the difference between PHP preg_match and Preg_match_all function
PHP Preg_match to match different country language instances
PHP uses Preg_match_all to solve the problem of Apache crash
The/u,/I,/s meanings in PHP preg_match regular match
PHP Preg_match function matches the string length problem
What does Preg_match isu in PHP mean?
PHP preg_match_all Regular Expression function usage explained
PHP preg_match Regular Expression Function example explained
JavaScript regular expression test () and exec () usage
Non-greedy pattern matching in PHP regular expressions
PHP Regular expression Efficiency greed, non-greed and backtracking analysis
JavaScript regular expression greedy and non-greedy modes
The global matching pattern analysis of the regular expressions in Javascript
JavaScript regular Expressions Match strings string
JS verification (judging) is the URL
PHP Regular Expression function usage instance
PHP preg_match functions and PHP Preg_match_al functions L instances, methods, examples
PHP Preg_match_all () function Use instance
PHP preg_match Regular Expression function instance
http://www.bkjia.com/PHPjc/1121388.html www.bkjia.com true http://www.bkjia.com/PHPjc/1121388.html techarticle PHP uses Preg_match_all to match the images in the article, and sometimes we need to use PHP to get the pictures in the page and save them, here we can use Preg_match_all to match the image to ...