Jump to content

Recommended Posts

Hello!

 

I was wondering if anyone can help me with attempting to load information on the following XML feed:

http://www.tfl.gov.uk/tfl/syndication/feeds/cycle-hire/livecyclehireupdates.xml

 

Into PHP. I only need information displayed for station ids 51,123 and 344.

 

Any advice or help would be much appreciated. I've attached the code I've used to load up RSS feeds. I'm using iwebkit to develop an iPhone friendly website.

 

Many thanks

rss.php

Link to comment
https://forums.phpfreaks.com/topic/273444-extracting-information-from-xml/
Share on other sites

Posting the code inline will get a lot more people looking at it.

 

I don't see anything unusual in the XML so a quick example using SimpleXML would be

$xml = new SimpleXMLElement("http://www.tfl.gov.uk/tfl/syndication/feeds/cycle-hire/livecyclehireupdates.xml", 0, true);
foreach ($xml->station as $station) {
   echo "At {$station->name} there are {$station->nbBikes} bikes and {$station->nbEmptyDocks} of {$station->nbDocks} empty docks\n";
}

 

[edit] You can target specific nodes with XPath.

foreach ($xml->xpath("station[id=51 or id=123 or id=344]") as $station) {

Edited by requinix
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.