码迷,mamicode.com
首页 > Web开发 > 详细

php实现解析网页并下载图片到本地

时间:2015-01-23 16:22:20      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:php   html      

<?php
//error_reporting(0);//关闭错误报告
include_once("simple_html_dom.php");//引入解析库
$url='http://www.w3cschool.cc/mongodb/mongodb-window-install.html';
$html=file_get_html($url);
while($url[strlen($url)-1]!='/')$url=substr($url,0,-1);//获得上层目录
if(!is_dir($filepath)){mkdir($_SERVER['DOCUMENT_ROOT']."/imgtmp/",1);}//创建目录
foreach($html->find('img') as $im)
{
	$p=$im->src;
	if($p[0]=='/'||$p[0]=='\\')$p=$url."..".$p;//补全url
	file_put_contents("imgtmp/".md5(microtime()).".".substr($p,-3),file_get_contents($p));
}
?>

php实现解析网页并下载图片到本地

标签:php   html      

原文地址:http://blog.csdn.net/qq754406613/article/details/43056661

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!