zhangxinba 发表于 2017-3-29 10:13:29

PHP下载CSS文件中的图片

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

//取得样式文件内容
$styleFileContent = file_get_contents('Public/Css/jtxm_Frame.css');

//匹配出需要下载的URL地址
preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray);

//循环需要下载的地址,逐个下载
$imagesURLArray = array_unique($imagesURLArray);
foreach($imagesURLArray as $imagesURL) {
        //根据实际情况修改路径!!
        //echo str_replace('..','Public',$imagesURL);
        file_put_contents(basename($imagesURL), file_get_contents(str_replace('..','Public',$imagesURL)));
}
页: [1]
查看完整版本: PHP下载CSS文件中的图片