kevin87 Posted January 25, 2014 Share Posted January 25, 2014 Hi everyone, I am having a little trouble understanding what is going on. Below is the code I am working with. The data is not printing on the screen. What the heck am I doing wrong? Any input is appreciated. Thanks, Kevin <?php $xmlMetar=simplexml_load_file("http://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=KARR&hoursBeforeNow=1"); $metarKARR=$xmlMetar->METAR->raw_text; echo $metarKARR; ?> Quote Link to comment https://forums.phpfreaks.com/topic/285675-pulling-weather-info-from-xml/ Share on other sites More sharing options...
Solution boompa Posted January 25, 2014 Solution Share Posted January 25, 2014 If you dump the value of $xmlMetar with print_r($xmlMetar), you get this: SimpleXMLElement Object ( [@attributes] => Array ( [version] => 1.2 ) [request_index] => 5490740 [data_source] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => metars ) ) [request] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => retrieve ) ) [errors] => SimpleXMLElement Object ( ) [warnings] => SimpleXMLElement Object ( ) [time_taken_ms] => 2 [data] => SimpleXMLElement Object ( [@attributes] => Array ( [num_results] => 1 ) [METAR] => SimpleXMLElement Object ( [raw_text] => KARR 251852Z 31023G33KT 10SM CLR M09/M19 A2972 RMK AO2 PK WND 30033/1846 SLP074 T10941189 [station_id] => KARR [observation_time] => 2014-01-25T18:52:00Z [latitude] => 41.77 [longitude] => -88.48 [temp_c] => -9.4 [dewpoint_c] => -18.9 [wind_dir_degrees] => 310 [wind_speed_kt] => 23 [wind_gust_kt] => 33 [visibility_statute_mi] => 10.0 [altim_in_hg] => 29.719488 [sea_level_pressure_mb] => 1007.4 [quality_control_flags] => SimpleXMLElement Object ( [auto_station] => TRUE ) [sky_condition] => SimpleXMLElement Object ( [@attributes] => Array ( [sky_cover] => CLR ) ) [flight_category] => VFR [metar_type] => METAR [elevation_m] => 215.0 ) ) ) As you can see, the METAR element is within a data element, so you must access that before METAR: $metarKARR=$xmlMetar->data->METAR->raw_text; Quote Link to comment https://forums.phpfreaks.com/topic/285675-pulling-weather-info-from-xml/#findComment-1466556 Share on other sites More sharing options...
kevin87 Posted January 25, 2014 Author Share Posted January 25, 2014 Awesome thank you so much! that did the trick. Kevin Quote Link to comment https://forums.phpfreaks.com/topic/285675-pulling-weather-info-from-xml/#findComment-1466561 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.