<?php 
require_once 'yanzheng.php';
set_time_limit(0);
print str_repeat(" ", 4096);  

function getSubstr($str, $leftStr, $rightStr)
	{
	
		$left = strpos($str, $leftStr); 
		$right = strpos($str, $rightStr,$left);
		if($left < 0 or $right < $left) return '';
		return substr($str, $left + strlen($leftStr), $right-$left-strlen($leftStr));
	
	} //字符串截取
	
	function caiji ($url){
	
		$curl = curl_init();
		
		// 设置你需要抓取的URL
		curl_setopt($curl, CURLOPT_URL, $url);
		
		// 设置header
		curl_setopt($curl, CURLOPT_HEADER, 1);
		
		// 设置cURL 参数，要求结果保存到字符串中还是输出到屏幕上。
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		
		// 运行cURL，请求网页
		$data = curl_exec($curl);
		
		// 关闭URL请求
		curl_close($curl);
		
		// 显示获得的数据
		return $data;
	
	} //CURL 采集

$time=date("Y-m-d");


$id=$_GET['id'];
$row=query("select * from url_data where user='$user' and id='$id'");
$myurl=$row['url'];//更新域名
$uptime=$row['uptime'];//更新时间

if($row){
	
	$url='http://seo.chinaz.com/'.$myurl;	
	$content=caiji($url);	
	$quanzhong=getSubstr($content,'baiduapp/','.gif');

	 ob_flush(); //初始化ob_flush函数
	 flush();  
	 sleep(3); //延迟3秒输出	
	    
	$url='http://www.baidu.com/s?wd=site:'.$myurl;	
	$content=caiji($url);
	
	preg_match('/找到相关结果数约(.*?)个/i',$content,$arra);
    preg_match('/<b style="color:#333">(.*?)<\/b>/i',$content,$arrb);

   $shoulu1=$arra[1];
   $shoulu1=str_replace(",","",$shoulu1);

   $shoulu2=$arrb[1];
   $shoulu2=str_replace(",","",$shoulu2);
   
   if($shoulu1){
   $baidu=$shoulu1;
   }else{
   $baidu=$shoulu2;
   }

	
	
	mysql_query("update url_data set baidu='$baidu',quanzhong='$quanzhong',uptime='$time' where id='$id'");	
	echo '更新成功';
   
}

ob_end_flush();  //结束 缓冲

?>
