龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

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

时间:2017-10-23 15:03来源:网络整理 作者:网络 点击:
分享到:
使用PHP下载CSS文件中的图片的代码 [代码片段(16行)]
    <?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));   
    }   
    ?>   
精彩图集

赞助商链接