topflight Posted October 12, 2009 Share Posted October 12, 2009 I have the following code that converts an RSS Feed into PHP, but when I go to view it, it is just a blob of text. Is their anyway I can just take the airport and the condition of that airport thanks. <?php function getFile($url) { $c = curl_init($url); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_HEADER, 0); $res = curl_exec($c); curl_close($c); return $res; } $i = getFile("http://www.flightstats.com/go/rss/airportdelays.do"); $xml = simplexml_load_string($i); foreach ($xml->channel->item as $k => $v) { print_r($v); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/177431-help-please/ Share on other sites More sharing options...
Mark Baker Posted October 12, 2009 Share Posted October 12, 2009 It will appear as just a long block of text unless you extract only the information you want to display, and put some html formatting in here foreach ($xml->channel->item as $k => $v) { print_r($v); } e.g. foreach ($xml->channel->item as $k => $v) { echo '<a href="'.$v->link.'">'; echo $v->guid; echo '</a><br />'; echo $v->title; echo '<hr />'; } Quote Link to comment https://forums.phpfreaks.com/topic/177431-help-please/#findComment-935554 Share on other sites More sharing options...
topflight Posted October 12, 2009 Author Share Posted October 12, 2009 But how do I know what the information is. For instance I want to get the airports and the condtion of the delaym how can I do that which the code above? Quote Link to comment https://forums.phpfreaks.com/topic/177431-help-please/#findComment-935556 Share on other sites More sharing options...
Mark Baker Posted October 12, 2009 Share Posted October 12, 2009 Do you have a form or screen that prompts the user to select which airport they want to look for? Quote Link to comment https://forums.phpfreaks.com/topic/177431-help-please/#findComment-935558 Share on other sites More sharing options...
topflight Posted October 12, 2009 Author Share Posted October 12, 2009 No I just want the page to show all the airport with the delays. Visit the following link: http://www.flightstats.com/go/rss/airportdelays.do I want to put all that information on my site but I want to change the font and eveything so thats why I want to convert it into php. Quote Link to comment https://forums.phpfreaks.com/topic/177431-help-please/#findComment-935568 Share on other sites More sharing options...
Mark Baker Posted October 12, 2009 Share Posted October 12, 2009 Well you can read what the information is by looking at the data returned by that link. Each item comprises four pieces of data: guid (which is some form of ID number for the list entry), title (which is the airport), description (which is exactly what it sounds like), and link (which is a url for more details) Quote Link to comment https://forums.phpfreaks.com/topic/177431-help-please/#findComment-935573 Share on other sites More sharing options...
topflight Posted October 12, 2009 Author Share Posted October 12, 2009 Yes but I can't find the variable guid and everything else. Quote Link to comment https://forums.phpfreaks.com/topic/177431-help-please/#findComment-935795 Share on other sites More sharing options...
topflight Posted October 13, 2009 Author Share Posted October 13, 2009 any other help please? Quote Link to comment https://forums.phpfreaks.com/topic/177431-help-please/#findComment-935831 Share on other sites More sharing options...
topflight Posted October 13, 2009 Author Share Posted October 13, 2009 ? Quote Link to comment https://forums.phpfreaks.com/topic/177431-help-please/#findComment-935900 Share on other sites More sharing options...
Mark Baker Posted October 13, 2009 Share Posted October 13, 2009 You would be advised to look at the code and see what it actually reads from the feed.... I've added some comments to help foreach ($xml->channel->item as $v) { // Display the delat reference ID ($v->guid) from the feed, as a link to the details for the delay ($v->link) echo '<a href="'.$v->link.'">'; echo $v->guid; echo '</a><br />'; // Display the name of the airport ($v->title) echo $v->title; echo '<br />'; // Display the description of the delay ($v->description) echo $v->description; echo '<hr />'; } The foreach loop loops through each item in the list, returning the following tags in $v <guid isPermaLink="false">BWI77180BWI</guid> <title>BWI (Balt./Wash. International Airport)</title> <description>This airport is experiencing arrival delays of 16 to 30 minutes due to Traffic Management Initiatives:EnRoute Sequencing Program since 13/07:05.</description> <link>http://www.flightstats.com/go/Airport/delays.do?airportCode=BWI&airportQueryDate=2009-10-13</link> Each of those can then be accessed using $v->guid, $v->title, $v->description and $v->link Quote Link to comment https://forums.phpfreaks.com/topic/177431-help-please/#findComment-936038 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.