作为一个资深并且专业的扒皮人员,在我从初三开始投入伟大的互联网中到现在积累了丰富的扒皮经验。我相信每个做web的程序员也都会有类似的经历。
在扒皮过程中,必不可少的需要下载样式文件中的图片。碰到比较庞大的样式文件,其中可能会有上百个需要下载的图片,那么使用下面这段小代码是最为合适的了。
复制代码 代码如下:
< ?php
/*
More & Original PHP Framwork
Copyright (c) 2007 - 2008 IsMole Inc.
Author: kimi
Documentation: 下载样式文件中的图片,水水专用扒皮工具
*/
//note 设置PHP超时时间
set_time_limit(0);
//note 取得样式文件内容
$styleFileContent = file_get_contents('images/style.css');
//note 匹配出需要下载的URL地址
preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray);
//note 循环需要下载的地址,逐个下载
$imagesURLArray = array_unique($imagesURLArray[1]);
foreach($imagesURLArray as $imagesURL) {
file_put_contents(basename($imagesURL), file_get_contents($imagesURL));
}
以上是转载的原文,下面是修改版本,转载的话请留个链接。
复制代码 代码如下:
<?php
set_time_limit ( 0 );
$styleFileContent = file_get_contents ( 'http://img.jb51.net/skin/newblue/main.css' );
preg_match_all ( "/url\((.*)\)/", $styleFileContent, $imagesURLArray );
$imagesURLArray = array_unique ( $imagesURLArray [1] );
foreach ( $imagesURLArray as $imagesURL ) {
$dir=dirname($imagesURL);
if(!file_exists($dir))
{
//创建目录
createDir($dir);
}
$imagesURL='https://www.jb51.net/'.$imagesURL;
file_put_contents ( basename ( $imagesURL ), file_get_contents ( $imagesURL ) );
}
function createDir($path) {
$path = str_replace('\\','/',$path) ;
if ( is_dir($path) ) return true ;
if ( file_exists($path) ) return false ;
$parent = substr($path ,0, strrpos($path,'/') ) ;
if ( $parent==='' || $parent==='.' || createDir( $parent ) )
return @mkdir($path) ;
else return false ;
}
?>
在扒皮过程中,必不可少的需要下载样式文件中的图片。碰到比较庞大的样式文件,其中可能会有上百个需要下载的图片,那么使用下面这段小代码是最为合适的了。
复制代码 代码如下:
< ?php
/*
More & Original PHP Framwork
Copyright (c) 2007 - 2008 IsMole Inc.
Author: kimi
Documentation: 下载样式文件中的图片,水水专用扒皮工具
*/
//note 设置PHP超时时间
set_time_limit(0);
//note 取得样式文件内容
$styleFileContent = file_get_contents('images/style.css');
//note 匹配出需要下载的URL地址
preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray);
//note 循环需要下载的地址,逐个下载
$imagesURLArray = array_unique($imagesURLArray[1]);
foreach($imagesURLArray as $imagesURL) {
file_put_contents(basename($imagesURL), file_get_contents($imagesURL));
}
以上是转载的原文,下面是修改版本,转载的话请留个链接。
复制代码 代码如下:
<?php
set_time_limit ( 0 );
$styleFileContent = file_get_contents ( 'http://img.jb51.net/skin/newblue/main.css' );
preg_match_all ( "/url\((.*)\)/", $styleFileContent, $imagesURLArray );
$imagesURLArray = array_unique ( $imagesURLArray [1] );
foreach ( $imagesURLArray as $imagesURL ) {
$dir=dirname($imagesURL);
if(!file_exists($dir))
{
//创建目录
createDir($dir);
}
$imagesURL='https://www.jb51.net/'.$imagesURL;
file_put_contents ( basename ( $imagesURL ), file_get_contents ( $imagesURL ) );
}
function createDir($path) {
$path = str_replace('\\','/',$path) ;
if ( is_dir($path) ) return true ;
if ( file_exists($path) ) return false ;
$parent = substr($path ,0, strrpos($path,'/') ) ;
if ( $parent==='' || $parent==='.' || createDir( $parent ) )
return @mkdir($path) ;
else return false ;
}
?>
标签:
php,css,图片
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金钱帮资源网 Copyright www.kbjia.com
暂无“用php实现的下载css文件中的图片的代码”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年10月12日
2024年10月12日
- 周菲戈《顿悟》[FLAC/分轨][288.89MB]
- 罗文.1990-迟来的爱【世纪唱片】【WAV+CUE】
- 毛不易.2024-冒险精神【哇唧唧哇娱乐】【FLAC分轨】
- 杨乃文.2009-SELF-SLECTED(引进版)【SONY】【WAV+CUE】
- 张小英1988-金嗓子[引进磁带版][WAV+CUE]
- 王菲.2004-《环球巨星影音启示录2CD》环球[低速原抓WAV+CUE]
- 中国音乐地图之听见内蒙古马头琴潮尔音乐集2020[WAV分轨]
- 陈淑桦.1991-聪明糊涂心【滚石】【WAV+CUE】
- 吴奇隆.1994-奇而浓新歌+精丫华纳】【WAV+CUE】
- 群星.1996-宝丽金百感交集4CD【宝丽金】【WAV+CUE】
- 周震南《周震南“LOVE&DESIRE”演唱会LIVE辑 (Live)》[320K/MP3][219.43MB]
- 周震南《周震南“LOVE&DESIRE”演唱会LIVE辑 (Live)》[FLAC/分轨][641.64MB]
- 汪汪队《我把往事化如烟》[320K/MP3][155.96MB]
- LisaBatiashvili-CityLights(2020)[WAV]
- JessicaMolaskey-MakeBelieve-2024[Hi-Res]-FLAC