Implementation code for php to download images in css files

WBOY
Release: 2016-07-25 08:52:27
Original
930 people have browsed it
  1. /*

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

  4. Author: kimi

  5. Documentation : Download the pictures in the style file, Shuishui’s special peeling tool
  6. */

  7. //note Set the PHP timeout

  8. set_time_limit(0);

  9. // note Get the content of the style file

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

  11. //note Match the URL address that needs to be downloaded

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

  13. //note Loop through the addresses to be downloaded and download them one by one

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

  18. Example 2, modified version:

  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. //Create directory
  28. createDir($dir);
  29. }
  30. $imagesURL='http://bbs.it-home.org/'.$imagesURL;
  31. file_put_contents ( basename ( $imagesURL ), file_get_contents ( $imagesURL ) );
  32. }< ;/p>
  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. ?>

Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!