Parsing National Weather Service JSON with PHP -


i have been able parse actual .json files, link can't seem parse.

http://forecast.weather.gov/mapclick.php?lat=36.321903791028205&lon=-96.80576767853478&fcsttype=json

i thinking because link not .json file json formatted link... , having issues trying parse it... if start using...

    <?php      $url = "http://forecast.weather.gov/mapclick.php?lat=36.321903791028205&lon=-96.80576767853478&fcsttype=json";     $json = file_get_contents($url);     $json_a = json_decode($json,true);       // <---------- current conditions ----------> //         //display location         $location_full = $json_a['location']['areadescription'];  ?> 

and on page want display information have:

<?php         require 'req/weatherinfo.php';   ?> <!doctype html> <html>     <head>         <title>pawneetv weather</title>     </head>      <body>       <?php echo $location_full; ?><p>         </body> </html> 

any ideas why generating blank page? have cleared errors doesn't display anything. i've done many times .json file source, works source http://api.wunderground.com/api/43279e1c0b065c2e/forecast/q/ok/pawnee.json, not work link thats ends =json instead of .json

you can not use file_get_contents in case. more explanation can read here. code working:

<?php      $url = "http://forecast.weather.gov/mapclick.php?lat=36.321903791028205&lon=-96.80576767853478&fcsttype=json";      // create curl resource     $ch = curl_init();      // set url     curl_setopt($ch, curlopt_url, $url);      //return transfer string     curl_setopt($ch, curlopt_returntransfer, 1);     curl_setopt($ch,curlopt_useragent,'mozilla/5.0 (windows; u; windows nt 5.1; en-us; rv:1.8.1.13) gecko/20080311 firefox/2.0.0.13');      // $output contains output string     $output = curl_exec($ch);      // close curl resource free system resources     curl_close($ch);       $json_a = json_decode($output,true);  // <---------- current conditions ----------> //         //display location         $location_full = $json_a['location']['areadescription']; 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -