The NWS implemented a requirement that all requests to forecast.weather.gov have a User-agent: header. You'll need to add a bit to your code before the file_get_contents() to establish a stream context with the headers needed. I use $opts = array(
'http'=>array(
'method'=>"GET",
'protocol_version' => 1.1,
'header'=>"Cache-Control: no-cache, must-revalidate\r\n" .
"Cache-control: max-age=0\r\n" .
"Connection: close\r\n" .
"User-agent: Forecast loader\r\n" .
"Accept: text/plain,text/html\r\n"
),
'https'=>array(
'method'=>"GET",
'protocol_version' => 1.1,
'header'=>"Cache-Control: no-cache, must-revalidate\r\n" .
"Cache-control: max-age=0\r\n" .
"Connection: close\r\n" .
"User-agent: Forecast loader\r\n" .
"Accept: text/plain,text/html\r\n"
)
);
$context = stream_context_create($opts);
then change the $xml = file_get_contents($url);
to $xml = file_get_contents($url,false,$context);
and the XML should be retrieved from forecast.weather.gov. The new forecast-v3.weather.gov requires HTTPS only, and this fix will support either http:// or https://