fork download
  1. <?php
  2. // Online PHP compiler to run PHP program online
  3. // Print "Try programiz.pro" message
  4. //echo "Try programiz.pro";
  5.  
  6. $city = "Abu Dhabi";
  7. $apiKey = "3fc94c21d6f0e3ece88d1dad4ed912d5";
  8. $googleApiUrl = "http://a...content-available-to-author-only...p.org/data/2.5/weather?q=".$city."&APPID=".$apiKey;
  9.  
  10. $ch = curl_init();
  11. curl_setopt($ch, CURLOPT_HEADER, 0);
  12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  13. curl_setopt($ch, CURLOPT_URL, $googleApiUrl);
  14. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  15. curl_setopt($ch, CURLOPT_VERBOSE, 0);
  16. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  17. $response = curl_exec($ch);
  18.  
  19. curl_close($ch);
  20. $data_cityname = json_decode($response);
  21. $cityId = $data_cityname->id;
  22. echo $cityId; die;
  23.  
  24.  
  25. ?>
Success #stdin #stdout #stderr 0.03s 26140KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Notice:  Trying to get property 'id' of non-object in /home/ZQlEQJ/prog.php on line 21