作为一个资深并且专业的扒皮人员,在我从初三开始投入伟大的互联网中到现在积累了丰富的扒皮经验。我相信每个做web的程序员也都会有类似的经历。

在扒皮过程中,必不可少的需要下载样式文件中的图片。碰到比较庞大的样式文件,其中可能会有上百个需要下载的图片,那么使用下面这段小代码是最为合适的了。

Php代码  收藏代码
  1. <?php  
  2. /* 
  3. More & Original PHP Framwork 
  4. Copyright (c) 2007 - 2008 IsMole Inc. 
  5. Author: kimi 
  6. Documentation: 下载样式文件中的图片,水水专用扒皮工具 
  7. */  
  8. //note 设置PHP超时时间  
  9. set_time_limit(0);  
  10. //note 取得样式文件内容  
  11. $styleFileContent = file_get_contents('images/style.css');  
  12. //note 匹配出需要下载的URL地址  
  13. preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray);  
  14. //note 循环需要下载的地址,逐个下载  
  15. $imagesURLArray = array_unique($imagesURLArray[1]);  
  16. foreach($imagesURLArray as $imagesURL) {  
  17. file_put_contents(basename($imagesURL), file_get_contents($imagesURL));  
  18. }  

 

来源:http://www.ccvita.com/375.html

posted on 2016-08-17 15:43  飘渺的悠远  阅读(163)  评论(0)    收藏  举报