当前位置: 移动技术网 > IT编程>开发语言>PHP > 使用PHP下载CSS文件中的图片的代码

使用PHP下载CSS文件中的图片的代码

2019年04月04日  | 移动技术网IT编程  | 我要评论
共享一段使用php下载css文件中的图片的代码
复制代码 代码如下:

<?php
//note 设置php超时时间
set_time_limit(0);

//note 取得样式文件内容
$stylefilecontent = file_get_contents('images/style.css');

//note 匹配出需要下载的url地址
preg_match_all("/url\((.*)\)/", $stylefilecontent, $imagesurlarray);

//note 循环需要下载的地址,逐个下载
$imagesurlarray = array_unique($imagesurlarray[1]);
foreach ($imagesurlarray as $imagesurl) {
file_put_contents(basename($imagesurl), file_get_contents($imagesurl));
}
?>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网