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

WBOY
풀어 주다: 2016-07-25 08:52:27
원래의
932명이 탐색했습니다.
  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('\\','/',$path) ;
  35. if ( is_dir($path) ) return true ;
  36. if ( file_exists($path) ) return false ;
  37. $parent = substr($path ,0, strrpos($path,'/') ) ;

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


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!