Jump to content

Help Please


topflight

Recommended Posts

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);
   }
?>

Link to comment
https://forums.phpfreaks.com/topic/177431-help-please/
Share on other sites

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 />';
}

Link to comment
https://forums.phpfreaks.com/topic/177431-help-please/#findComment-935554
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/177431-help-please/#findComment-935568
Share on other sites

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)

Link to comment
https://forums.phpfreaks.com/topic/177431-help-please/#findComment-935573
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/177431-help-please/#findComment-936038
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.