Home  >  Article  >  Backend Development  >  Teach you how to quickly match pictures in articles in php in one minute

Teach you how to quickly match pictures in articles in php in one minute

藏色散人
藏色散人forward
2021-09-17 16:32:333234browse

Teach you how to quickly match pictures in articles in php in one minute!

It’s very simple, just one function can do it!

The following teaches you how to use preg_match_all in php to match pictures in articles                                                                                                                        

##preg_match_all function:

int preg_match_all ( string pattern, string subject, array matches [, int flags] )
Perform a global regular expression matching

Search in the subject for all content that matches the regular expression given by pattern and put the results into matches in the order specified by flags.

After the first match is found, subsequent searches start from the end of the previous match.

flags can be a combination of the following flags (note that it does not make sense to use PREG_PATTERN_ORDER and PREG_SET_ORDER together):

PREG_PATTERN_ORDER Sort the results so that $matches[0] is an array of all pattern matches, $ matches[1] is an array of strings matched by the subpattern in the first bracket, and so on!

$pattern="//";
$con = file_get_contents("https://www.jb51.net/news/jb-1.html");
preg_match_all($pattern,$con,$match);
print_r($match);

Teach you how to quickly match pictures in articles in php in one minute

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of Teach you how to quickly match pictures in articles in php in one minute. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete