Use PHP to download the code for the images in the CSS file

  • 2020-09-16 07:25:31
  • OfStack

Share 1 piece of code that USES PHP to download images from the CSS file
 
<?php 
//note  Set up the PHP timeout  
set_time_limit(0); 

//note  Gets the contents of the style file  
$styleFileContent = file_get_contents('images/style.css'); 

//note  Match what needs to be downloaded URL address  
preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray); 

//note  Loop through the addresses you need to download, one at a time  
$imagesURLArray = array_unique($imagesURLArray[1]); 
foreach ($imagesURLArray as $imagesURL) { 
file_put_contents(basename($imagesURL), file_get_contents($imagesURL)); 
} 
?> 

Related articles: