I'm making this script which reads of the BBC RSS weather. Unfortunatly it isnt displaying the RSS. Have I got my nodes mixed up or somthing?

<?php

function xml_via_proxy ($url) {
$context = stream_context_create(
array('http'=>
array('proxy'=>'cache.uwe.ac.uk:8080')
));

$contents = file_get_contents($url, false, $context);
return simplexml_load_string($contents);

};

$weather = xml_via_proxy("http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/0105.xml");

$description = $weather->rss->channel->item->description;

?>
<table border="1">
<h1>EALA</h1>
<tr><td>Description</td><td><?php print $description ?></td></tr>

</table>

    So what does a var_dump of $weather give you... I'm thinking you might not need "rss->"....

    Well, after doing a bit of debugging myself, the proxying of it didn't work. So once I took out the proxy, and just used file_get_contents() it worked. Well, it got the information. After I removed the "rss->" (as stated above) it worked. So my final working code was this:

    <?php
    
    function xml_via_proxy ($url) {
    	/*$context = stream_context_create(
    	array('http'=>
    		array('proxy'=>'cache.uwe.ac.uk:8080')
    		)
    	);*/
    	$contents = file_get_contents($url, false, $context);
    	return simplexml_load_string($contents);
    }
    
    $weather = xml_via_proxy("http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/0105.xml");
    $description = $weather->channel->item->description;
    
    ?>

      Oh i love you!
      That solved it, I owe you a beer, whenever your in Bristol give me a shout 🙂

      Oh btw, the proxy is there so it can be viewed outside of the university. When used on a standard webserver, you are right.

        Okay. Makes a bit more sense. Anywho, glad I could help out!!

        OH!!

        And to help explain this a bit more, the simplexml object defaults to the first node. In this case, the first node is the <rss></rss> node. So next time you work on something like this, you'll know. The object base is from the root node 😉

          lol, Actually that does help, I have another 5 of those to make :p

            12 days later

            hi
            the function simplexml_load_string doesn't work on my server since i don't have php 5
            so what else can i do to use this rss script
            thx

              You could use [man]file_get_contents/man to get the XML feed, and then run a quick RegEx to extrapolate the information you require.

              Look at the articles on phpbuilder.com (the main site) and you'll see one titled "Simple Remoting" which should help you out.

                Write a Reply...