使用PHP下載CSS文件中的圖片的代碼
更新時間:2013年09月24日 09:50:48 作者:
CSS文件中的圖片在以前不知道該如何下載,而現(xiàn)在卻可以使用php簡單實現(xiàn)了,具體的如下,感興趣的朋友可以參考下
共享一段使用PHP下載CSS文件中的圖片的代碼
<?php
//note 設置PHP超時時間
set_time_limit(0);
//note 取得樣式文件內(nèi)容
$styleFileContent = file_get_contents('images/style.css');
//note 匹配出需要下載的URL地址
preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray);
//note 循環(huán)需要下載的地址,逐個下載
$imagesURLArray = array_unique($imagesURLArray[1]);
foreach ($imagesURLArray as $imagesURL) {
file_put_contents(basename($imagesURL), file_get_contents($imagesURL));
}
?>
復制代碼 代碼如下:
<?php
//note 設置PHP超時時間
set_time_limit(0);
//note 取得樣式文件內(nèi)容
$styleFileContent = file_get_contents('images/style.css');
//note 匹配出需要下載的URL地址
preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray);
//note 循環(huán)需要下載的地址,逐個下載
$imagesURLArray = array_unique($imagesURLArray[1]);
foreach ($imagesURLArray as $imagesURL) {
file_put_contents(basename($imagesURL), file_get_contents($imagesURL));
}
?>
您可能感興趣的文章:
相關文章
PHP模擬登陸163郵箱發(fā)郵件及獲取通訊錄列表的方法
這篇文章主要介紹了PHP模擬登陸163郵箱發(fā)郵件及獲取通訊錄列表的方法,實例分析了php實用curl模擬登陸163郵箱的操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03PHP數(shù)據(jù)庫操作四:mongodb用法分析
這篇文章主要介紹了PHP數(shù)據(jù)庫操作mongodb用法,結合實例形式較為詳細的分析了MongoDB的功能、安裝、基本命令、使用方法及相關注意事項,需要的朋友可以參考下2017-08-08