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

WBOY
Freigeben: 2016-07-25 08:52:27
Original
932 Leute haben es durchsucht
  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. ?>
复制代码


Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!