Home >Backend Development >PHP Tutorial >How to get all the images in the web page and store them in an array_PHP tutorial
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:
3 45 12 13 |
$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); } } |