我在罗伯·珀西瓦尔的完整网页开发课程中,并被困在挑战项目:天气刮刀。试着从网站上获取天气信息,但不起作用。提前感谢
<?php
$contents = file_get_contents("http://www.weather-forecast.com/locations/San-Francisco/forecasts/latest");
preg_match('/3 Day Weather Forecast Summary:<\/b><span class="read-more-small"><span class="read-more-content"> <span class="phrase"> (.*?) </s', $contents, $matches);
echo $matches[1];
?>发布于 2016-07-13 21:39:29
我正在上同样的课程,一小时后我终于想出了怎么做!如果太晚了,很抱歉,但我希望它能帮助其他人寻找答案。
我不知道为什么你的不起作用,但以下是对我有效的原因:
preg_match('/3 Day Weather Forecast Summary:<\/b><span class="read-more-small"><span class="read-more-content"> <span class="phrase">(.*?)<\/span>/',
$contents, $matches);
print_r($matches[1]);
发布于 2016-04-20 19:40:23
在<span class="phrase">之后,html中没有空白空间。
来自网站的Html:
3 Day Weather Forecast Summary:</b><span class="read-more-small"><span class="read-more-content"> <span class="phrase">Light rain (total 5mm)试试这个:
if (preg_match('/3 Day Weather Forecast Summary:<\/b><span class="read-more-small"><span class="read-more-content"> <span class="phrase">(.*?)</s', $contents, $matches)) {
echo $matches[1];
}https://stackoverflow.com/questions/36753503
复制相似问题