Home  >  Article  >  Backend Development  >  一个php采集类,含上载远程图片并替换原文

一个php采集类,含上载远程图片并替换原文

WBOY
WBOYOriginal
2016-06-13 13:02:57794browse

一个php采集类,含下载远程图片并替换原文

今天没事完善了一个php采集类,这给大家分享下。

本实例,可以,自动下载远程图片,并替换文章中的图片地址。。。

实例下载地址   http://download.csdn.net/detail/open520yin/4899183

实例:

<?php header("Content-Type: Text/Html");
 $url = "http://sh.sina.com.cn/travel/message/2012-12-16/191225659_5.html";
  include("Snoopy.class.php");
  $snoopy = new Snoopy;
  $snoopy->fetch($url); //获取所有内容
  $html = $snoopy->results; //显示结果
  $title = $snoopy->getTitle();//获取标题
  $text = $snoopy->getCent('<div class='\"(.*)\"' id='\"artibody\"'>','<p class='\"page\"'>');//获取主体
//替换规则
$arr = array(
	0=>'<span id='\"_function_code_page\"'>(.*?)</span>',
	1=>'<a href="%5C%22(.*)html#page_pic%5C%22">',
	2=>'</a>',
	3=>'</p>
<div class='\"article-video' artice-pic vid='\"\"'></div>',
	4=>'</div>',
	5=>'<a name="%5C%22page_pic%5C%22">',
	6=>'<!--(.*)-->',
	7=>'<span class='\"img_descr\"'>(.*?)</span>',
);
 $text = $snoopy->replace($text,$arr);//过滤

echo $snoopy->saveImg($text);  //下载远程图片,并替换文章图片地址
?></a>

有需要的朋友,可以自己下载再完善。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn