As a senior and professional Skinner personnel, I began to invest in the great Internet from the beginning to now accumulated a wealth of Skinner experience. I'm sure every web programmer will have a similar experience.
In the Skinner process, it is essential to download the pictures in the style file. When you encounter a larger style file, which may have hundreds of pictures to download, it is most appropriate to use this small piece of code below.
Copy Code code as follows:
< PHP
/*
More & Original PHP framwork
Copyright (c) 2007-2008 Ismole Inc.
Author:kimi
Documentation: Download the pictures in the style file, water-specific Skinner tools
*/
Note Set the PHP timeout time
Set_time_limit (0);
Note To get the contents of the style file
$styleFileContent = file_get_contents (' images/style.css ');
The note matches the URL address that needs to be downloaded
Preg_match_all ("/url\ (. *) \)/", $styleFileContent, $imagesURLArray);
Note Cycle need to download the address, download one by one
$imagesURLArray = Array_unique ($imagesURLArray [1]);
foreach ($imagesURLArray as $imagesURL) {
File_put_contents (basename ($imagesURL), file_get_contents ($imagesURL));
}
The above is reproduced in the original text, the following is a modified version, reproduced words please leave a link.
Copy Code code as follows:
<?php
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 table of contents
Createdir ($dir);
}
$imagesURL = ' http://www.jb51.net/'. $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;
}
?>