用php实现的下载css文件中的图片的代码
php  /  管理员 发布于 7年前   184
在扒皮过程中,必不可少的需要下载样式文件中的图片。碰到比较庞大的样式文件,其中可能会有上百个需要下载的图片,那么使用下面这段小代码是最为合适的了。 Author: kimi //note 设置PHP超时时间 //note 取得样式文件内容 //note 匹配出需要下载的URL地址 //note 循环需要下载的地址,逐个下载 function createDir($path) { $parent = substr($path ,0, strrpos($path,'/') ) ;
< ?php
/*
More & Original PHP Framwork
Copyright (c) 2007 - 2008 IsMole Inc.
Documentation: 下载样式文件中的图片,水水专用扒皮工具
*/
set_time_limit(0);
$styleFileContent = file_get_contents('images/style.css');
preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray);
$imagesURLArray = array_unique($imagesURLArray[1]);
foreach($imagesURLArray as $imagesURL) {
file_put_contents(basename($imagesURL), file_get_contents($imagesURL));
}
以上是转载的原文,下面是修改版本,转载的话请留个链接。 复制代码 代码如下:
set_time_limit ( 0 );
$styleFileContent = file_get_contents ( 'http://img..net.cn/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=''.$imagesURL;
file_put_contents ( basename ( $imagesURL ), file_get_contents ( $imagesURL ) );
}
$path = str_replace('\\','/',$path) ;
if ( is_dir($path) ) return true ;
if ( file_exists($path) ) return false ;
if ( $parent==='' || $parent==='.' || createDir( $parent ) )
return @mkdir($path) ;
else return false ;
}
?> 您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号