php下载css中图片代码

提供一个常见的php下载css中图片代码,只要把$url填写好就行了,代码如下:

  1. <?php
  2. $url = 'http://www.phpfensi.com';
  3. $data = file_get_contents('abc.css');
  4. preg_match('/(.*//.*?)//',$url,$host);
  5. $host = $host[1];
  6. if (!is_dir('img')) { mkdir('img'); }
  7. $regex = '/url('{0,1}"{0,1}(.*?)'{0,1}"{0,1})/';
  8. preg_match_all($regex,$data,$result);
  9. foreach ($result[1] as $val) {
  10. if (preg_match('/^http.*/',$val)) { $target = $val; }
  11. else if (preg_match('/^/.*/',$val)) { $target=$host.$val; }
  12. else { $target=$url.$val; }
  13. echo $target."<br/>rn";
  14. preg_match('/.*/(.*.D+)$/',$val,$name);
  15. if (!is_file('./img/'.$name[1])) {
  16. copy($target,'./img/'.$name[1]);
  17. }
  18. }?>