提供一个常见的php下载css中图片代码,有需要的朋友可以下载,只要把$url填写好就行了哈。
代码如下 | 复制代码 |
$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." preg_match('/.*/(.*.D )$/',$val,$name); if (!is_file('./img/'.$name[1])) { copy($target,'./img/'.$name[1]); } }?> |