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

来源:互联网 发布:协方差矩阵公式cov方差 编辑:程序博客网 时间:2024/06/04 19:16
php实现下载CSS文件中的图片。
 
共享一段使用PHP下载CSS文件中的图片的代码 
[php] view plaincopy
  1. <?php   
  2. //note 设置PHP超时时间   
  3. set_time_limit(0);   
  4.   
  5.   
  6. //note 取得样式文件内容   
  7. $styleFileContent = file_get_contents('images/style.css');   
  8.   
  9.   
  10. //note 匹配出需要下载的URL地址   
  11. preg_match_all("/url\((.*)\)/"$styleFileContent$imagesURLArray);   
  12.   
  13. //参考自:www.jbxue.com  
  14. //note 循环需要下载的地址,逐个下载   
  15. $imagesURLArray = array_unique($imagesURLArray[1]);   
  16. foreach ($imagesURLArray as $imagesURL) {   
  17. file_put_contents(basename($imagesURL), file_get_contents($imagesURL));   
  18. }   
  19. ?>