Home>Article>Backend Development> Can there be images in a php array?

Can there be images in a php array?

藏色散人
藏色散人 Original
2021-11-30 10:38:09 1681browse

php数组里能有图片,php获取图片并存入数组的方法是:1、创建一个PHP示例文件;2、通过php正则匹配及数组操作获取网页里所有图片并存入数组即可。

Can there be images in a php array?

本文操作环境:windows7系统、PHP7.4版、DELL G3电脑

php数组里能不能有图片?

php获取网页里所有图片并存入数组的方法

这篇文章主要介绍了php获取网页里所有图片并存入数组的方法,涉及php正则匹配及数组操作的技巧

具体如下:

$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); } }

推荐学习:《PHP视频教程

The above is the detailed content of Can there be images in a php array?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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