PHP extracts and downloads the image address in the css file
Release: 2016-07-25 08:52:14
Original
1456 people have browsed it
-
- /**
- * Get the image address in CSS and save it locally
- */
- class getInCssImage
- {
- /**
- * Save the picture
- * @param $cssUrl css url address
- * @param $dir The directory where the picture is saved
- * @return void
- */
- static public function saveImage($cssUrl, $dir)
- {
- $content = file_get_contents($cssUrl) ;
- $patterns = '/images(.*).(jpg|gif|png)/'; //regex needs to be transformed according to different addresses
- 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.plcxue.com/".$image; //The address to be captured
- readfile($imageUrl);
- $img = ob_get_contents();
- ob_end_clean();
- $size = strlen ($img);
- $localImage = $dir. strchr($image, '/'); //Save the local image address
- $fp = fopen($localImage, 'a');
- fwrite($fp, $img);
- fclose($fp);
- }
- }
- }
- $content = getInCssImage::saveImage('/css/css.css', 'image');
Copy code
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31