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

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

Jul 29, 2016 am 08:53 AM
match php

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.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles