html5中文学习网

您的位置: 首页 > 网络编程 > PHP编程 » 正文

使用PHP下载CSS文件中的图片的代码_php技巧_脚本之家

[ ] 已经帮助:人解决问题
共享一段使用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));
}
?>
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助