当前位置:首页 > PHP教程 > PHP高级教程

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

共享一段使用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));
}
?>

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!