【发布时间】:2013-05-31 12:02:04
【问题描述】:
我有以下网站: http://stationmeteo.meteorologic.net/metar/your-metar.php?icao=LFRS&day=070308
我想从中提取数据。 我尝试使用 file_get_contents 和一些正则表达式,但有些东西不起作用。
这是我尝试过的代码:
$content=file_get_contents('http://stationmeteo.meteorologic.net/metar/your-metar.php? icao=LFMN&day=010513');
preg_match('/00\:30 07\/03\/2008(.+)01\:30 07\/03\/2008/',$content,$m);
echo $m[0];
echo $m[1];
它给了我未定义的偏移量 0 和 1。 如果我将网页的内容直接复制到 $content 而不是使用 file_get_contents,它可以正常工作。
我错过了什么?
【问题讨论】:
-
当你使用
file_get_contents(...)时,你在$content中得到了什么? -
你没有得到匹配,因为没有与
00:00 01/05/2013匹配的时间戳? -
抱歉我把日期设置错了,我的意思是,00:30 07/03/2008 和 01:30 07/03/2008
-
file_get_contents是否返回了一些东西? -
是的,如果我回显$content,它将返回网站的内容。