php下载css中图片代码
提供一个常见的php下载css中图片代码,只要把$url填写好就行了,代码如下:
- <?php
- $url = 'http://www.phpfensi.com';
- $data = file_get_contents('abc.css');
- preg_match('/(.*//.*?)//',$url,$host);
- $host = $host[1];
- if (!is_dir('img')) { mkdir('img'); }
- $regex = '/url('{0,1}"{0,1}(.*?)'{0,1}"{0,1})/';
- preg_match_all($regex,$data,$result);
- foreach ($result[1] as $val) {
- if (preg_match('/^http.*/',$val)) { $target = $val; }
- else if (preg_match('/^/.*/',$val)) { $target=$host.$val; }
- else { $target=$url.$val; }
- echo $target."<br/>rn";
- preg_match('/.*/(.*.D+)$/',$val,$name);
- if (!is_file('./img/'.$name[1])) {
- copy($target,'./img/'.$name[1]);
- }
- }?>