Home > Backend Development > PHP Tutorial > 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

藏色散人
Release: 2023-04-10 16:56:01
forward
3276 people have browsed it

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] )
Copy after login
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);
Copy after login

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!

Related labels:
php
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template