时间:2019-07-07加入收藏
$url = "http://www.boc.cn/sourcedb/whpj/";
$queryServer = curl_init();
curl_setopt($queryServer, CURLOPT_URL, $url);
curl_setopt($queryServer, CURLOPT_HEADER, 0);
curl_setopt($queryServer, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($queryServer, CURLOPT_RETURNTRANSFER, true);
curl_setopt($queryServer, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($queryServer, CURLOPT_TIMEOUT, 30);
$html = curl_exec($queryServer);
$html = iconv('UTF-8','GBK//IGNORE',$html); //如果你需要是的数据是utf-8编码的,这一行可以注销,如果需要gbk编码的,请保留.如果出现乱码,就是一行的问题,你自己调着试吧
//echo $holder;exit; 此处可以输出来测试.
$html = str_replace(array("\n","\r","\t"),"",$html);
$preg = '/<table\s+width=\"800\"[^>]+>(.*?)<\/table>/';
preg_match_all($preg,$html,$out);
//匹配每行
preg_match_all('/<tr[^>]+>(.*?)<\/tr>/',$out[1][0],$tr);
//匹配每个td
$result = array();
$match = '/<td.+>([^<]+)<\/td>/U';
foreach( $tr[0] as $key => $value ){
preg_match_all($match,$value,$arr);
$result[] = $arr[1];
}
//输出测试,$result就是你要的数据,至于你要怎么输出显示格式,那就随心调就好了。
foreach( $result as $key => $value ){
echo implode("\t",$value);
echo "<br>";
}
exit;
TGA: php