是这样的,我采集一点彩票开奖数据,
写了正则匹配,以经匹配出来了正确的结果数组($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场半全场
*
*/
解决方案 »
- 弱弱的问一下,做网站的需要学PHP吗?
- PHP中怎样在模板页里嵌套循环
- 请教一个简单的包含html文件的问题
- select count(*)报错,请大家指点
- Sort Headers of a table
- PHP outputObject的问题。急!!!
- 数据库连接失败:mysql_error:Access denied for user 'root'@'localhost'
- 求助:刚学SMARTY模板,按照网上讲得做,但使用assign方法时老是出现问题,弄了一下午,都快疯了!!!
- 小菜鸟求助!!!请大虾帮忙!!!
- checkbox问题!
- [请教达人]关于php5和libiconv进行交叉编译的问题[急!!!]
- 用什么方法能改变数组的第一个下标,并且用dump()打印出来用的是新的下标。代码如下
但是呢,我在本地测式的时候,有时候都会卡一下,本地应该不会存在get方法慢的原因吧。
当然ajax请求服务器也是需要时间来缓存的。