一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php 利用curl模仿用户采集远程网站内容

时间:2010-05-20 编辑:简简单单 来源:一聚教程网

 代码如下 复制代码

$timestamp = time();
function open($file,$type=''){
        global $fromurl,$referer;
        $cachename=$file;
                if($type){
                        $file='/'.$type.'/'.$file;
                }else{
                        $file=$file;
                }
                        if($open=file($file)){
                                        $count=count($open);
                                        for($i=0;$i<$count;$i++){
                                                $theget.=$open[$i];
                                        }
                                }else{
                                        die('无法连接源站网络,请刷新');
                                }
        return $theget;
}

function cut($file,$from,$end){
        $message=explode($from,$file);
        $message=explode($end,$message[1]);
return        $message[0];
}

function curl($openurl)
{
 global $isfun;
 if($isfun=="curl"){
 $ch = curl_init($openurl);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 $file = curl_exec($ch);
 curl_close($ch);
 }
 elseif($isfun=="fopen"){
  $file=open($openurl);
 }
 else{ echo "";}
 return $file;
}

//使用方法

 代码如下 复制代码
$url = 'http://www.111com.net';
$content = open($url,0);

/*
下面的函数用来判断函数是否可用
*/

 代码如下 复制代码

function isfun($funName)
 {
        return (false !== function_exists($funName))?YES:NO;
 }
?>

热门栏目