PHP Get CSS file image address download save to local _php tutorial

Source: Internet
Author: User
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. .

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