• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

用php实现的下载css文件中的图片的代码_php技巧

php 搞代码 3年前 (2022-01-26) 18次浏览 已收录 0个评论

作为一个资深并且专业的扒皮人员,在我从初三开始投入伟大的互联网中到现在积累了丰富的扒皮经验。我相信每个做web的程序员也都会有类似的经历。

在扒皮过程中,必不可少的需要下载样式文件中的图片。碰到比较庞大的样式文件,其中可能会有上百个需要下载的图片,那么使用下面这段小代码是最为合适的了。

 <BR>< ?php <BR>/* <BR>More & Original PHP Framwork <BR>Copyright (c) 2007 - 2008 IsMole Inc. <br><br>Author: kimi <BR>Documentation: 下载样式文件中的图片,水水专用扒皮工具 <BR>*/ <br><br>//note 设置PHP超时时间 <BR>set_time_limit(0); <br><br>//note 取得样式文件内容 <BR>$styleFileContent = file_get_contents('images/style.css'); <br><br>//note 匹配出需要下载的URL地址 <BR>preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray); <br><br>//note 循环需要下载的地址,逐个下载 <BR>$imagesURLArray = array_unique($imagesURLArray[1]); <BR>foreach($imagesURLArray as $imagesURL) { <BR>file_put_contents(basename($imagesURL), file_<a style="color:transparent">本@文来源gao($daima.com搞@代@#码(网5</a><strong>搞gaodaima代码</strong>get_contents($imagesURL)); <BR>} <BR>


以上是转载的原文,下面是修改版本,转载的话请留个链接。

 <BR><?php <BR>set_time_limit ( 0 ); <BR>$styleFileContent = file_get_contents ( 'http://img.jb51.net/skin/newblue/main.css' ); <BR>preg_match_all ( "/url\((.*)\)/", $styleFileContent, $imagesURLArray ); <BR>$imagesURLArray = array_unique ( $imagesURLArray [1] ); <BR>foreach ( $imagesURLArray as $imagesURL ) { <BR>$dir=dirname($imagesURL); <BR>if(!file_exists($dir)) <BR>{ <BR>//创建目录 <BR>createDir($dir); <BR>} <BR>$imagesURL='http://www.gaodaima.com/'.$imagesURL; <BR>file_put_contents ( basename ( $imagesURL ), file_get_contents ( $imagesURL ) ); <BR>} <br><br>function createDir($path) { <BR>$path = str_replace('\\','/',$path) ; <BR>if ( is_dir($path) ) return true ; <BR>if ( file_exists($path) ) return false ; <br><br>$parent = substr($path ,0, strrpos($path,'/') ) ; <BR>if ( $parent==='' || $parent==='.' || createDir( $parent ) ) <BR>return @mkdir($path) ; <BR>else return false ; <BR>} <BR>?> <BR>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:用php实现的下载css文件中的图片的代码_php技巧
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址