当前位置:编程学习 > php >>

php 采集器

本款文章是一款用php实现的文章采集功能哦,只是一个简单的功能不过源码也就很少了,适合于小型的采集功能哦。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
set_time_limit(0);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<?php

 $filecontent = getcontent('http://zzzyk.com');
 $start = 's;
 $end ='b;
 $art = 311;
 $str = '';


 preg_match('/<title>(.+?)</title>/', $filecontent, $arr);/* 取得标题*/
  $init =explode($start,$filecontent); 
 $array = explode($end,$init[1]);
 $str =$str.$arr[1].replaceHtml($array[0]);

function getcontent($url)
 {  
  $retmsg=file_get_contents($url);
  return $retmsg;
 }

function savato($filename,$content){
 if( !empty( $content ) ){
  $info = fopen($filename,'w+');
  fwrite($info,$content);
  fclose($info);
  echo "保存文件 $filename 成功<br>";
 }else{
  echo '文章更新失败,<a href=get.php >点击重新更新</a>';
 }
}

function replaceHtml($str){
 $temp = str_replace(' ',' ',$str);
 $temp = str_replace('<BR>',chr(10),$temp);
 $ return strip_tags($temp);
 }
 


 ?>
</body>
</html>

补充:Php教程,Php高级应用 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,