【发布时间】:2025-12-22 14:00:19
【问题描述】:
我是 php 新手,我创建了一个 scraper.php 页面,您可以在其中从“http://www.weather-forecast.com”检索任何给定城市的天气信息。
我跟着教练,我看不出为什么我的代码返回一个空白页,而它应该只返回一个简短的 3 天预测
无论如何...这是我的代码
<?php
$city=$_GET['city'];
$city=str_replace(" ","",$city);
$contents=file_get_contents("http://www.weather-forecast.com/locations/".$city."/forecasts/latest");
preg_match('/3 Day Weather Forest Summary:<\/b>
<span class="phrase">(.*?)</span>',$contents, $matches);
echo $matches[1];
?>
【问题讨论】:
-
你试过调试吗? $city 是什么?你在 $contents 中得到了什么?等
标签: php file-get-contents str-replace