请帮我检查一下这段代码。我想我的正则表达式写了一个问题,但我不知道如何解决它:为什么使用curl和正则表达式时数据为空
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$content = get_data('http://ibongda.vn/lich-thi-dau-bong-da.hs');
$regex = '/<div id="zone-schedule-group-by-season">(.*)<\/div>/';
preg_match($regex, $content, $matches);
$table = $matches[1];
print_r($table);
不使用正则表达式解析html – 2014-10-20 02:31:03
该错误不在您的正则表达式中,它在您的设计中。正则表达式不是解析HTML的正确工具。我建议看看HTML解析器的'汤'家族之一 - 一目了然http://simplehtmldom.sourceforge.net/看起来是一个不错的选择。 – 2014-10-20 02:33:57
我尝试simpledomhtml,但它很慢。我的托管有php 5.3,所以我不能使用最新的goutte版本。我不知道其他方式:( – 2014-10-20 02:34:52