PHP Gets the image address in the CSS file and downloads it to the local method,
This example describes how PHP gets the image address in the CSS file and downloads it locally. Share to everyone for your reference.
The specific implementation code is as follows:
The
copy Code code is as follows:
/**
* get picture address in CSS, and save to local
*/
Class Getincssimage
{
/**
* Picture warranty Save the
* @param $cssUrl The URL address of the CSS
* @param the directory where the picture is saved
* @return void
*/
static public function sav Eimage ($CSSURL, $dir)
{
$content = file_get_contents ($CSSURL);
$patterns = '/images (. *). (jpg|gif|png)/'; The regular transforms the
Preg_match_all ($patterns, $content, $matches) according to different addresses;
$imagesUrls = $matches [0];
if (!is_dir ($dir))
mkdir (DirName (__file__). '/'. $dir, 0777);
foreach ($imagesUrls as $image)
{
Ob_start ();
$imageUrl = "http://www.xxxx.com/". $image;//This address fills in the address you want to crawl
ReadFile ($IMAGEURL);
$img = ob_get_contents ();
Ob_end_clean ();
$size = strlen ($img);
$localImage = $dir. STRCHR ($image, '/');//Save to local image address
$fp = fopen ($localImage, ' a ');
Fwrite ($fp, $img);
Fclose ($FP);
}
}
}
$content = Getincssimage::saveimage ('/css/css.css ', ' image ');
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/920612.html www.bkjia.com true http://www.bkjia.com/PHPjc/920612.html techarticle PHP Gets the image address of the CSS file and download to the local method, this article describes the PHP get the image address in the CSS file and download to the local method. Share to everyone for your reference. ...