Download the image code in the css file using php _ PHP Tutorial

Source: Internet
Author: User
Download the image code in the css file using php. As a senior and professional suede engineer, I have accumulated rich experience in the Internet since I started my junior year. I believe that every web programmer will also have a senior and professional hacker who has accumulated rich experience in the Internet since I started my junior year. I believe that every web programmer will have similar experiences.

You must download the images in the style file. If you encounter a large style file that may contain hundreds of images to be downloaded, the following small code is the most suitable.

The code is as follows:


<? Php
/*
More & Original PHP Framwork
Copyright (c) 2007-2008 IsMole Inc.

Author: kimi
Documentation
*/

// Note: Set the PHP timeout.
Set_time_limit (0 );

// Note: get the style file content
$ StyleFileContent = file_get_contents ('images/style.css ');

// The note matches the URL to be downloaded.
Preg_match_all ("/url \ (. *) \)/", $ styleFileContent, $ imagesURLArray );

// Download the addresses to be downloaded in the note loop one by one
$ ImagesURLArray = array_unique ($ imagesURLArray [1]);
Foreach ($ imagesURLArray as $ imagesURL ){
File_put_contents (basename ($ imagesURL), file_get_contents ($ imagesURL ));
}


The above is the original reprinted text, and the following is a modified version. if you reprint the text, please leave a link.

The code is as follows:


Set_time_limit (0 );
$ StyleFileContent = file_get_contents ('http: // img.jb51.net/skin/newblue/main.css ');
Preg_match_all ("/url \ (. *) \)/", $ styleFileContent, $ imagesURLArray );
$ ImagesURLArray = array_unique ($ imagesURLArray [1]);
Foreach ($ imagesURLArray as $ imagesURL ){
$ Dir = dirname ($ imagesURL );
If (! File_exists ($ dir ))
{
// Create a directory
CreateDir ($ dir );
}
$ ImagesURL = 'http: // www.jb51.net/'.w.imagesurl;
File_put_contents (basename ($ imagesURL), file_get_contents ($ imagesURL ));
}

Function createDir ($ path ){
$ Path = str_replace ('\', '/', $ path );
If (is_dir ($ path) return true;
If (file_exists ($ path) return false;

$ Parent = substr ($ path, 0, strrpos ($ path ,'/'));
If ($ parent = ''| $ parent = '.' | createDir ($ parent ))
Return @ mkdir ($ path );
Else return false;
}
?>

Bytes. I believe that every web programmer will also have...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.