PHP uses preg_match_all to match pictures in articles. What does match mean? match function sid not matc

WBOY
Release: 2016-07-29 08:53:16
Original
1318 people have browsed it

Sometimes we need to use php to get images from web pages and save them. Here we can use preg_match_all to match the image address. Coders in need can refer to

preg_match_all function:
int preg_match_all ( string pattern, string subject, array matches [, int flags] ) performs a global regular expression match, searches the subject for all content that matches the regular expression given by pattern and puts the results into matches in the order specified by flags.​ ​
After searching for the first match, 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 the array matching all patterns, and $matches[1] is the first bracket. An array of strings matched by the subpattern, and so on!

Example:

<?<span>php
</span><span>$con</span> = <span>file_get_contents</span>("http://www.xxx.com/news/jb-1.html"<span>);
</span><span>$pattern</span>="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/"<span>;
</span><span>preg_match_all</span>(<span>$pattern</span>,<span>$con</span>,<span>$match</span><span>);
</span><span>print_r</span>(<span>$match</span><span>);
</span>?> 
Copy after login

Result:

<span>Array</span><span>(
    [</span>0] => <span>Array</span><span>        (
            [</span>0] => <img src="http://www.xxx.com/usr/themes/dddefault/images/logo.png" alt="php preg match,php preg match all,filesmatch php,php preg match函数,php中preg match,match,puma match,match交友网站,itunes match订购,itunes match,服饰间的搭配match,mix match,match是什么意思,match函数,sid not matc" /><span>            [</span>1] => <img title="码农教程上线了" src="http://www.xxx.com/usr/uploads/2012/09/531656480.jpg" alt="php preg match,php preg match all,filesmatch php,php preg match函数,php中preg match,match,puma match,match交友网站,itunes match订购,itunes match,服饰间的搭配match,mix match,match是什么意思,match函数,sid not matc" /><span>            [</span>2] => <img src="http://www.xxx.com/usr/uploads/2012/09/2647136297.jpg" alt="php preg match,php preg match all,filesmatch php,php preg match函数,php中preg match,match,puma match,match交友网站,itunes match订购,itunes match,服饰间的搭配match,mix match,match是什么意思,match函数,sid not matc" /><span>        )
    [</span>1] => <span>Array</span><span>        (
            [</span>0] => http:<span>//</span><span>www.xxx.com/usr/themes/dddefault/images/logo.png</span>            [1] => http:<span>//</span><span>www.xxx.com/usr/uploads/2012/09/531656480.jpg</span>            [2] => http:<span>//</span><span>www.xxx.com/usr/uploads/2012/09/2647136297.jpg</span><span>        )
)</span>
Copy after login

Original address: http://www.manongjc.com/article/708.html

Related reading:

php preg_match_all combined with str_replace to replace all img in the content

Analysis of the difference between php preg_match and preg_match_all functions

php preg_match matching examples of languages ​​in different countries

Solution to the apache crash problem caused by PHP using preg_match_all

The meaning of /u, /i, /s in php preg_match regular matching

The problem of the string length matched by the php preg_match function

What does preg_match isU mean in php

php preg_match_all regular expression function usage explanation

php preg_match regular expression function example explanation

javascript regular expression test() and exec( ) Usage

php Non-greedy pattern matching in regular expressions

php Regular expression efficiency greedy, non-greedy and backtracking analysis

javascript Regular expression greedy mode and non-greedy mode

Global matching of regular expressions in Javascript Pattern analysis

javascript regular expression matching string string

js verification (judgment) whether it is a URL

php regular expression function usage examples

php preg_match function and php preg_match_al function l examples, methods, examples

php preg_match_all () function usage example

php preg_match regular expression function example

The above introduces how PHP uses preg_match_all to match the pictures in the article, including the content of match and PHP. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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