[ "method" => "GET", "header" => implode("\r\n", [ "Accept: application/json, text/javascript, */*; q=0.01", "Accept-Language: en-US,en;q=0.9", "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/115.0 Safari/537.36", "Referer: http://www.bom.gov.au/", "Connection: close", ]), "timeout" => 10, // 10 seconds timeout ] ]; $context = stream_context_create($options); $response = @file_get_contents($url, false, $context); if ($response === false) { echo "Unable to fetch data. Possible network or access issue."; exit; } $data = json_decode($response, true); if ($data === null) { echo "Failed to decode JSON."; exit; } if (isset($data['observations']['data'][0]['air_temp'])) { $temp = $data['observations']['data'][0]['air_temp']; $temp_str = preg_replace('/\D/', '', (string)$temp); $first_two = substr($temp_str, 0, 2); echo " " . $first_two; } else { echo "00"; } ?>