Jump to content

simplexml_load_file help, please


woolyg

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/115496-simplexml_load_file-help-please/
Share on other sites

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

 

Archived

This topic is now archived and is closed to further replies.

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