weather.php 812 B

1234567891011121314151617181920212223242526
  1. <?php
  2. function weather_results($response)
  3. {
  4. $json_response = json_decode($response, true);
  5. if ($json_response)
  6. {
  7. $current_weather = $json_response["current_condition"][0];
  8. $temp_c = $current_weather["temp_C"];
  9. $temp_f = $current_weather["temp_F"];
  10. $description = $current_weather["weatherDesc"][0]["value"];
  11. $formatted_response = "$description - $temp_c °C | $temp_f °F";
  12. $source = "https://wttr.in";
  13. return array(
  14. "special_response" => array(
  15. "response" => htmlspecialchars($formatted_response),
  16. "source" => $source
  17. )
  18. );
  19. }
  20. }
  21. ?>