Home > Backend Development > PHP Tutorial > How to get all the images in the web page and store them in an array_PHP tutorial

How to get all the images in the web page and store them in an array_PHP tutorial

WBOY
Release: 2016-07-13 09:58:03
Original
849 people have browsed it

How to get all the pictures in the web page and store them in an array in php

This article describes the method of getting all the pictures in the web page in php and storing them in an array. Share it with everyone for your reference. The details are as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

$images = array();

preg_match_all('/(img|src)=("|')[^"'>] /i', $data, $media);

unset($data);

$data=preg_replace('/(img|src)("|'|="|=')(.*)/i',"",$media[0]);

foreach($data as $url)

{

$info = pathinfo($url);

if (isset($info['extension']))

{

if (($info['extension'] == 'jpg') ||

($info['extension'] == 'jpeg') ||

($info['extension'] == 'gif') ||

($info['extension'] == 'png'))

array_push($images, $url);

}

}

1 2

3

4

5

7 8 9 10 11
12 13
14 15 16
$images = array(); preg_match_all('/(img|src)=("|')[^"'>] /i', $data, $media); unset($data); $data=preg_replace('/(img|src)("|'|="|=')(.*)/i',"$3",$media[0]); foreach($data as $url) { $info = pathinfo($url); if (isset($info['extension'])) { if (($info['extension'] == 'jpg') || ($info['extension'] == 'jpeg') || ($info['extension'] == 'gif') || ($info['extension'] == 'png')) array_push($images, $url); } }
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/979667.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/979667.htmlTechArticleHow to get all the pictures in the web page and store them in an array in php. This article explains how to get all the pictures in the web page in php. method of entering an array. Share it with everyone for your reference. The details are as follows:...
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