PHP implementation of CSS file background Image Downloader code, _php tutorial

Source: Internet
Author: User
Tags php programming

PHP implementation of the CSS file background image Downloader code,


This article describes the PHP implementation of the CSS file background image Downloader code. Share to everyone for your reference. The implementation method is as follows:

Download CSS files inside the background image is the long-term activities of our pirates, download a CSS Image downloader often appear a variety of advertising pop-up window, really can't carry. Here is a PHP version of the CSS file background image downloader for everyone.

Put the file in the PHP program directory dos php.exe cssimages.php 0 http://www.xxxx.com/css/style.css \images\

First in the PHP program directory to build a images folder, hehe, paste code:
Copy CodeThe code is as follows: <?php
/**
*@ o Tang 2013-4-6 22:19
*@ hehe
*/
Set_time_limit (0);
Error_reporting (E_error);
if ($ARGC <4) {
Print_r ('
+-------------------------------------------------+
usage:php '. $argv [0]. ' CSS path type (0 for remote, 1 for local) CSS file path picture save directory
Example:
Php.exe '. $argv [0]. ' 0 Http://www.xxx.com/index.css \images\
+-------------------------------------------------+
');
Exit ();
}
Remote CSS
if ($argv [1]==0) {
$host = Getparse ($argv [2], ' host ');
$savePath = Getsavepath ($argv [3]);
$images = Getcssimagesarray ($argv [2]);
Print_r ($images);
$imagesurls = Getimageslinks ($images, $argv [2]);
Imagesdowner ($imagesurls);
}
Local CSS Start
if ($argv [1]==1) {
Too lazy to write, oh, this does not mean much
}
/*
* CSS Image analysis function
* $csspath CSS file path
*/
function Getcssimagesarray ($csspath) {
$cssFile = file_get_contents ($csspath);
$images = Array ();
Preg_match_all ("|url\ ((. +) \) |i", $cssFile, $images);
$images = $images [1];
return $images;
}
/*
* CSS file relative to directory processing function
* $path Path
*/
function Getnocsspath ($path) {
Global $host;
$tempLinkmages = ";
Considerable path acquisition
$tempPath = explode ('/', $path);
for ($i =1; $i < (COUNT ($tempPath)-2); $i + +) {
$tempLinkmages. = $tempPath [$i]. ' /';
}
$xdImage = $host. $tempLinkmages;
return $xdImage;
Considerable path acquisition
}

/*
* Picture Connection Get function
* $images array of all images to be fetched
* Csslink CSS File links
*/
function Getimageslinks ($imagesArray, $cssLink) {
Global $host;
$urlImages = Array ();
foreach ($imagesArray as $key = = $value) {
if (Pathcheck ($value)) {
if ((!in_array ($host. $value), $urlImages))) {
$urlImages [$key] = $host. $value;
}
}else{
if ((!in_array (Getnocsspath ($cssLink, ' path '). $value), $urlImages))) {
$urlImages [$key] = Getnocsspath (Getparse ($cssLink, ' path '). $value;
}
}
}
return $urlImages;
}

/*
* Image Capture
* $urlImages An array of images to download
*/
function Imagesdowner ($urlImages) {
Print_r ($urlImages);
foreach ($urlImages as $key = = $value) {
$urlImagesOk [$key] = Str_replace ('//', '/', $value);
$urlImagesOk [$key] = Str_replace (' "', '", $urlImagesOk [$key]);
$urlImagesOk [$key] = Str_replace ("'", "", $urlImagesOk [$key]);
$urlImagesOk [$key] = ' http://'. $urlImagesOk [$key];
if (Grabimage ($urlImagesOk [$key],basename ($urlImagesOk [$key])) {
Print_r (
BaseName ($urlImagesOk [$key]). ' File Download successful
');
}else{
Print_r (
BaseName ($urlImagesOk [$key]). ' Download failed
');
}
}
Print_r ($URLIMAGESOK);
}
/*
* Relative path absolute path determination function
* $IMAGEURL Image Link Array
* True for absolute path
* False for the equivalent path
*/
function Pathcheck ($IMAGEURL) {
if (Preg_match (' |^ (\ \) | ', $IMAGEURL)) {
return true;
}else{
return false;
}
}

/*
* Image Download function
* $url Image Link
* $filename Picture Name
*/
function Grabimage ($url, $filename) {
Global $savePath;
if ($url = = ") {
return false; Returns False if the $url is empty;

}
$ext _name = STRRCHR ($url, '. '); Get the name extension of a picture
if ($ext _name! = '. gif ' && $ext _name! = '. jpg ' && $ext _name! = '. bmp ' && $ext _name! = '. png ') {
return false; Format is not in allowed range

}
if ($filename = = ") {
return false; Invalid name

}
Start capturing
Ob_start ();
if (ReadFile ($url)) {
$img _data = ob_get_contents ();
Ob_end_clean ();
$size = strlen ($img _data);
}else{
Ob_end_clean ();
return false;
}
if ($local _file = fopen ($savePath. $filename, ' a ') && (fwrite ($local _file, $img _data)))
{
Fclose ($local _file);
return true;
}
}
/*
* Save Directory
*/
function Getsavepath ($savepath) {
$savePath = $savepath;
$savePath = DirName (__file__). $savePath;
return $savePath;
}
/*
* Parse URL
*/
function Getparse ($host, $type) {
$baseurl = Parse_url ($host);
return $baseurl [$type]. ' /';

Echo $baseurl;
}
?>

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/909332.html www.bkjia.com true http://www.bkjia.com/PHPjc/909332.html techarticle PHP Implementation of the CSS file background Image Downloader code, this article describes the PHP implementation of the CSS file background image Downloader code. Share to everyone for your reference. The concrete implementation method is as follows: ...

  • 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.