php下载css文件中图片的实现代码

原创
2016-07-25 08:52:27 686浏览
  1. /*

  2. More & Original PHP Framwork
  3. Copyright (c) 2007 - 2008 IsMole Inc.

  4. Author: kimi

  5. Documentation: 下载样式文件中的图片,水水专用扒皮工具
  6. */

  7. //note 设置PHP超时时间

  8. set_time_limit(0);

  9. //note 取得样式文件内容

  10. $styleFileContent = file_get_contents('images/style.css');

  11. //note 匹配出需要下载的URL地址

  12. preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray);

  13. //note 循环需要下载的地址,逐个下载

  14. $imagesURLArray = array_unique($imagesURLArray[1]);
  15. foreach($imagesURLArray as $imagesURL) {
  16. file_put_contents(basename($imagesURL), file_get_contents($imagesURL));
  17. }

  18. 例2,修改版:

  19. set_time_limit ( 0 );
  20. $styleFileContent = file_get_contents ( 'http://img.jbxue.com/skin/newblue/main.css' );
  21. preg_match_all ( "/url\((.*)\)/", $styleFileContent, $imagesURLArray );
  22. $imagesURLArray = array_unique ( $imagesURLArray [1] );
  23. foreach ( $imagesURLArray as $imagesURL ) {
  24. $dir=dirname($imagesURL);
  25. if(!file_exists($dir))
  26. {
  27. //创建目录
  28. createDir($dir);
  29. }
  30. $imagesURL='http://bbs.it-home.org/'.$imagesURL;
  31. file_put_contents ( basename ( $imagesURL ), file_get_contents ( $imagesURL ) );
  32. }

  33. function createDir($path) {

  34. $path = str_replace('\\','//m.sbmmt.com/m/',$path) ;
  35. if ( is_dir($path) ) return true ;
  36. if ( file_exists($path) ) return false ;

  37. $parent = substr($path ,0, strrpos($path,'//m.sbmmt.com/m/') ) ;

  38. if ( $parent==='' || $parent==='.' || createDir( $parent ) )
  39. return @mkdir($path) ;
  40. else return false ;
  41. }
  42. ?>

复制代码


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
上一条:php返回数组资料mysql_fetch_array()函数 下一条:php css文件背景图片下载器实现代码

相关文章

查看更多