是这样的,我采集一点彩票开奖数据,
写了正则匹配,以经匹配出来了正确的结果数组($result)
但是呢,速度有一点慢,所以想请高手看看,有没有什么办法优化一下速度。代码入下:
$str = file_get_contents('http://baidu.lehecai.com/lottery/draw/?agentId=5555');
preg_match('/<table cellpadding="0" cellspacing="0" class="kj_tab">(.*)<\/table>/isU', $str, $strs);
preg_match_all('/(<tr>|<tr[^>]*>)(.*)<\/tr>/isU', $strs[0] , $output );
foreach($output[2] as $value){
preg_match_all('/(<td>|<td[^>]*>)(.*)<\/td>/isU',$value ,$va);
$result[] = $va[2];
}for($i = 2, $size =count($result); $i < $size ; $i++){
preg_match_all('/<a[^>]* href="([^"]*)"[^>]*>(.*)<\/a>/isU', $result[$i][0], $href);
preg_match_all('/(<a[^>]*>|<span[^>]*>)(.*)(<\/a>|<\/span>)/isU', $result[$i][3], $matches);
$result[$i][0] = "http://baidu.lehecai.com/".$href[1][0];
$result[$i][3] = $matches[2];
}//preg_match_all('/<a[^>]*>(.*)<\/a>/isU', $result[3][3][3], $matches);
//$result[3][3][3] = preg_replace("/[\s]+/si","",$matches[1][0]);
$result[3][3][3] = preg_replace("/[\s]+/si","",$result[3][3][3]);
$result[3][3][3] = preg_replace("/\(.*\)/si","",$result[3][3][3]);
//echo "<pre>"; print_r($result);exit();/*
* $result 说明 $result[$i][3] 为号码数 ; $result[$i][0] 为连接 ; $result[$i][1] 为开奖期数 ;
* $i的说明如下表 :
* 2:双色球
* 3:福彩3D
* 4:七乐彩
* 5:华东15选5
* 6:东方6+1
* 8:大乐透
* 9:排列三
* 10:排列五
* 11:七星彩
* 12:22选5
* 13:14场胜负彩
* 14:任选9场
* 15:4场进球彩
* 16:6场半全场
*
*/
写了正则匹配,以经匹配出来了正确的结果数组($result)
但是呢,速度有一点慢,所以想请高手看看,有没有什么办法优化一下速度。代码入下:
$str = file_get_contents('http://baidu.lehecai.com/lottery/draw/?agentId=5555');
preg_match('/<table cellpadding="0" cellspacing="0" class="kj_tab">(.*)<\/table>/isU', $str, $strs);
preg_match_all('/(<tr>|<tr[^>]*>)(.*)<\/tr>/isU', $strs[0] , $output );
foreach($output[2] as $value){
preg_match_all('/(<td>|<td[^>]*>)(.*)<\/td>/isU',$value ,$va);
$result[] = $va[2];
}for($i = 2, $size =count($result); $i < $size ; $i++){
preg_match_all('/<a[^>]* href="([^"]*)"[^>]*>(.*)<\/a>/isU', $result[$i][0], $href);
preg_match_all('/(<a[^>]*>|<span[^>]*>)(.*)(<\/a>|<\/span>)/isU', $result[$i][3], $matches);
$result[$i][0] = "http://baidu.lehecai.com/".$href[1][0];
$result[$i][3] = $matches[2];
}//preg_match_all('/<a[^>]*>(.*)<\/a>/isU', $result[3][3][3], $matches);
//$result[3][3][3] = preg_replace("/[\s]+/si","",$matches[1][0]);
$result[3][3][3] = preg_replace("/[\s]+/si","",$result[3][3][3]);
$result[3][3][3] = preg_replace("/\(.*\)/si","",$result[3][3][3]);
//echo "<pre>"; print_r($result);exit();/*
* $result 说明 $result[$i][3] 为号码数 ; $result[$i][0] 为连接 ; $result[$i][1] 为开奖期数 ;
* $i的说明如下表 :
* 2:双色球
* 3:福彩3D
* 4:七乐彩
* 5:华东15选5
* 6:东方6+1
* 8:大乐透
* 9:排列三
* 10:排列五
* 11:七星彩
* 12:22选5
* 13:14场胜负彩
* 14:任选9场
* 15:4场进球彩
* 16:6场半全场
*
*/
但是呢,我在本地测式的时候,有时候都会卡一下,本地应该不会存在get方法慢的原因吧。
当然ajax请求服务器也是需要时间来缓存的。