Heim >php教程 >PHP源码 >采集彩票双色球数据与简单统计

采集彩票双色球数据与简单统计

PHP中文网
PHP中文网Original
2016-05-25 17:12:521674Durchsuche

        跳至                

采集与统计
	期数
	期差<option value="5" >5<option value="10" >10<option value="15" >15<option value="20" >20main($start, $end)){
		echo &#39;采集完成&#39;; 	
	}	
}else{
	
	$qishu = isset($_GET[&#39;qishu&#39;]) ? intval($_GET[&#39;qishu&#39;]) : 0;
	$cha =isset($_GET[&#39;cha&#39;]) ? intval($_GET[&#39;cha&#39;]) : 0;

	$chas = &#39;chas&#39;.$cha;
	$$chas = &#39;selected="selected"&#39;;	

	if($_GET){
		$_list = $Ss->detachNum();
		$list = array();
		$n = $i = $qishu;
		$num_arr = array();
		for( $i; $i = $qishu-$cha; $n-- ){
			if(!in_array($n, $num_arr))
				$num_arr[] = $n;
		}
		sort($num_arr);
		$list = array();
		foreach($num_arr as $key => $val){
			$list[] = $_list[$val];
		}
		$dispose = $Ss->dataDispose( $list, $qishu);
		$red = $dispose[&#39;red&#39;];
		$blue = $dispose[&#39;blue&#39;];
?>期数红蓝 $val){
	$style = &#39;&#39;;
	if($val[0]==$qishu){
		$style="style=&#39;background: #EBE6A9;&#39;";	
	}
?><tr >红次数权值均值<?php
for($i=1;$i蓝次数权值均值<?php
for($i=1;$i
" _ue_custom_node_="true">
_list = $this->getFile();
		for( $i=$start; $i<=$end; $i++ ){
			$url = str_ireplace(&#39;*&#39;,$i,$this->purl);
			$this->getContent($url);
		}
		return true;
	}
	function getContent($url){
		$ch = curl_init(); 
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$data = curl_exec($ch);
		if(!$data){
			return &#39;&#39;;	
		} 
		# 切割整个页面
		$content = explode(&#39;&#39;,$data);
		$content = explode(&#39;&#39;,$content[1]);

		# 匹配数据
		preg_match_all("/(.*?)<\/tr>/is", $content[0] ,$out);

		unset($out[1][0]);
		$con_all = $out[1];
		$qishu = null;
		ob_start();
		foreach($con_all as $key => $val){
			preg_match("/(.*?)<\/td>/", $val,$matches_1);
			$title = $matches_1[2];
			preg_match("/<\/td>/", $val,$matches_2);
			$value = $matches_2[2];
			$str = trim($title.&#39;:&#39;.$value);	
			if(!in_array($str,$this->_list)){	  
				echo "\n".$str; 
			}
		}
		$ob_content = ob_get_contents();
		ob_end_clean();
		$this->saveFile($ob_content);
		
	}
	#保存文件
	function saveFile($data){
		if(!is_file($this->files)){
			$fp = fopen($this->files,&#39;w+&#39;);		
		}else{
			$fp = fopen($this->files,&#39;a+&#39;);
		}
		fwrite($fp, $data);
		fclose($fp);
	}
	#取文件 为数组
	function getFile(){
		$arr = array();
		if(!is_file($this->files)){
			return $arr;	
		}
		$fp = fopen($this->files,&#39;r&#39;);
		while (!feof($fp)) {
			$arr[] = trim(fgets($fp));
		}
		fclose($fp);
		return $arr;
	}
	function detachNum(){
		$file_list = $this->getFile();
		array_shift($file_list);
		$reu = array();
		foreach($file_list as $key => $val){
			$temp = $this->getLayout($val);
			$reu[$temp[0]] = $temp;
		}
		return $reu;
	}
	function getLayout($data){
		$reu = array();
		$reu = explode(&#39;:&#39;,$data);
		$reu[2] = substr($reu[1], -2, 2);	
		$reu[1] = substr($reu[1],0,strlen($reu[1])-2);
		return $reu;
	}
	# 数据处理
	function dataDispose($data,$qishu){
		if(!is_array($data)) return false;
		$coun = count($data);
		$foolr = floor($coun/2);
		$foolr_qishu = $foolr+1;
		$red = array();
		$blue = array();
		$num = 1;
		foreach($data as $key => $val){
			if($val[0] == $qishu){	 
				$num = $foolr;
				$weight_num = $foolr_qishu;
			}elseif($val[0]<$qishu){	
				$weight_num = $num ++;	
			}elseif($val[0]>$qishu){	
				$weight_num = $num --;	
			}  
			# 红
			$son_arr = $this->stringNumber($val[1]);
			foreach($son_arr as $k2 => $v2){ 
				$red[intval($v2)][&#39;hits&#39;] = $red[intval($v2)][&#39;hits&#39;]+1; 
				$red[intval($v2)][&#39;weight&#39;] = $red[intval($v2)][&#39;weight&#39;]+$weight_num; 
			} 
			# 蓝
			$blue[intval($val[2])][&#39;hits&#39;] = $blue[intval($val[2])][&#39;hits&#39;]+1; 
			$blue[intval($val[2])][&#39;weight&#39;] = $blue[intval($val[2])][&#39;weight&#39;]+$weight_num; 
		}
		
		for( $i=0; $i<=33 ;$i++ ){
			if($red[$i]){
				$red[$i][&#39;mean&#39;] = round($red[$i][&#39;hits&#39;]/$red[$i][&#39;weight&#39;],2) ;
			}
			
		}
		for( $i=0; $i<=16 ;$i++ ){
			
			if($blue[$i]){
				$blue[$i][&#39;mean&#39;] = round($blue[$i][&#39;hits&#39;]/$blue[$i][&#39;weight&#39;],2);
			}
		}
		return array( &#39;red&#39;=>$red, &#39;blue&#39;=>$blue);
	}
	function stringNumber($string){
		$list = array();
		$list[] = substr($string, 0, 2);	
		$list[] = substr($string, 2, 2);	
		$list[] = substr($string, 4, 2);	
		$list[] = substr($string, 6, 2);	
		$list[] = substr($string, 8, 2);	
		$list[] = substr($string, 10, 2);

		return $list;
	}
//	function dbMysql(){
//		$conn = mysql_connect(&#39;localhost&#39;,&#39;root&#39;,&#39;root&#39;) or die(&#39;连接Mysql错误:&#39;.mysql_error());
//		mysql_select_db(&#39;caipiao&#39;,$conn) or die(&#39;连接数据库错误:&#39;.mysql_error());
//		mysql_query(&#39;set names gbk&#39;);
//	}
}
// 采集数据
//$start = 1;
//$end = 1;
//$Ss = new getSseqiu();
//$Ss->main($start, $end);
?>


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:php上传图片Nächster Artikel:PHP 生成友好URL 【用于SEO】