Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.