woolyg Posted July 18, 2008 Share Posted July 18, 2008 Hi, I'm trying to bring an RSS feed from another site onto mine, and am trying to use the simplexml_load_file() function to do so. The below code returns the exit('Failed to open xml.') bit - can anyone see what I'm doing wrong here? <?php if (file_exists('http://www.OTHER_SITE.com/rss/ptv/page/ArticleIndex/0,,12306~2233528,00.xml')) { $xml = simplexml_load_file('http://www.OTHER_SITE.com/rss/ptv/page/ArticleIndex/0,,12306~2233528,00.xml'); print_r($xml); } else { exit('Failed to open xml.'); } ?> Can anyone point me in the right direction? Thanks, WoolyG Quote Link to comment Share on other sites More sharing options...
ratcateme Posted July 18, 2008 Share Posted July 18, 2008 what version of php are you using reading php.net it appares it won't work for url's on php less than 5.0.0 Scott. sorry the file_exists function. Quote Link to comment Share on other sites More sharing options...
woolyg Posted July 18, 2008 Author Share Posted July 18, 2008 OK - thanks for the reply. I've ascertained that the server is definitely using PHP5, and these functions should work. From an online tutorial, I'm using the following code (you should be able to copy it and place it into any PHP file on a live server and run it: <?php # INSTANTIATE CURL. $curl = curl_init(); # CURL SETTINGS. curl_setopt($curl, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/122933.rss"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); # GRAB THE XML FILE. $xmlTwitter = curl_exec($curl); //echo $xmlTwitter; curl_close($curl); # SET UP XML OBJECT. $xmlObjTwitter = simplexml_load_string( $xmlTwitter ); $tempCounter = 0; foreach ( $xmlObjTwitter -> item as $item ) { # DISPLAY ONLY 10 ITEMS. if ( $tempCounter < 11 ) { echo "<li><a href=\"{$item -> guid}\">{$item -> title}</a></li> "; } $tempCounter += 1; } ?> - which should show the RSS feed on my page. If I un-comment "echo $xmlTwitter;" , it displays all of the XML data - but I can't select any of it to display using # SET UP XML OBJECT. $xmlObjTwitter = simplexml_load_string( $xmlTwitter ); Can anyone shed some light on why $xmlObjTwitter won't work? Thanks, WoolyG Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.