| code as follows |
copy code |
|
/**
* Get image address in CSS and save to local
*/
Class Getincssimage
{
/**
* Picture saved
* @param URL address of $cssUrl CSS
* @param $dir directory to save pictures
* @return void
*/
static public Function SaveImage ($CSSURL, $dir)
{
$content = file_get_contents ($CSSURL);
$patterns = '/images (. *). (jpg|gif|png)/'; Regular according to the different address needs to transform
Preg_match_all ($patterns, $content, $matches);
$imagesUrls = $matches [0];
if (!is_dir ($dir))
mkdir (DirName (__file__). '/'. $dir, 0777);
foreach ($imagesUrls as $image)
{
Ob_start ();
$IMAGEURL = "http://www.xx.com/". $image; This address was originally obtained using a program. Lazy, down.
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 ');
|
http://www.bkjia.com/PHPjc/633161.html www.bkjia.com true http://www.bkjia.com/PHPjc/633161.html techarticle the code below copies the code/** * Get the image address in the CSS, and save to Local */class Getincssimage {/** * picture saved * @param $cssUrl CSS URL address * @param $dir save. .