Chinaunix首页 | 论坛 | 博客
  • 博客访问: 308174
  • 博文数量: 128
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1611
  • 用 户 组: 普通用户
  • 注册时间: 2013-08-19 11:49
文章分类

全部博文(128)

文章存档

2018年(2)

2016年(2)

2014年(10)

2013年(114)

我的朋友

分类: PHP

2013-09-25 10:45:41

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

点击(此处)折叠或打开

  1. <?php
  2. //note 设置PHP超时时间
  3. set_time_limit(0);

  4. //note 取得样式文件内容
  5. $styleFileContent = file_get_contents('images/style.css');

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

  8. //note 循环需要下载的地址,逐个下载
  9. $imagesURLArray = array_unique($imagesURLArray[1]);
  10. foreach ($imagesURLArray as $imagesURL) {
  11. file_put_contents(basename($imagesURL), file_get_contents($imagesURL));
  12. }
  13. ?>

阅读(583) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~