Page 1 of 1

Pulling XML with PHP Problem

Posted: Sat Nov 21, 2009 11:09 am
by forkinhell
I think this should be pretty easy, but for some reason I have spent all day trying to get it to work and failing. (probably due to my inexperience)

All I need to do is get an object, say <description>, from this XML URL: http://themoneyconverter.com/GBP/rss.xml to echo out on the page.

The XML is a list of all currency rates against the GBP.

Any help would be really great.

I have been trying things along the lines of:

Code: Select all

$from = "GBP";
    $url = "http://themoneyconverter.com/$from/rss.xml";
 
$xml = simplexml_load_file($url);
 
    $namespaces = $xml->getDocNamespaces(TRUE);
    var_dump($namespaces);
 

Re: Pulling XML with PHP Problem

Posted: Sat Nov 21, 2009 7:20 pm
by Jonah Bron
So, does it work? If not, what error do you get? If you haven't already, you should do some reading on this.

http://www.ibm.com/developerworks/libra ... lphp1.html

Re: Pulling XML with PHP Problem

Posted: Sat Nov 21, 2009 7:46 pm
by forkinhell
Yeh thanks, that helped. I've ended up with this that seems to work:

Code: Select all

 
$xmlobj = simplexml_load_file("http://themoneyconverter.com/GBP/rss.xml");
 
echo $xmlobj->channel->item [0]->title;
echo "<br />";
echo $xmlobj->channel->item [0]->description;
 
on to the next problem...