views:

63

answers:

2
    <?php
$twitter_url = 'http://twitter.com/statuses/user_timeline/ishrikrishna.xml?count=1';

$buffer = file_get_contents($twitter_url);

$xml = new SimpleXMLElement($buffer);

$status = $xml -> status;

$tweet =  $status -> text;

echo $tweet;

?>

I used this code to fetch tweets and it works successfully on localhost but not on my webhost, I tried this script on two webhosting services.

The problem i've noticed is that functions like file_get_contents(), simplexml_load_file() failed to fetch data from xml file(ex. rss files) stored on another server.

is there any solution's u know. Thanks in advance.

A: 

I believe this means you have the fopen URL wrappers turned off. See http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen You will probably not be able to turn these on if you are using a shared web server.

You may be able to use cURL to fetch remote pages instead:

$ch = curl_init('http://twitter.com/statuses/user_timeline/ishrikrishna.xml?count=1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$buffer = curl_exec($ch);

This will only work you have the cURL extension installed and enabled on your webhost.

See the PHP cURL documentation: http://www.php.net/manual/en/book.curl.php

Edit: corrected curl_setopt call

lonesomeday
Curl also not works, Is there anyway to install and use our own php version on webpages or is there any methode to enable extentions like simplexml via .htaccess file.
Shrikrishna Meena
No, you can only enable the fopen wrappers in php.ini, and I expect a webhost that has them turned off will not allow you to enable them. It is perfectly possible that you do not have the ability to load remote files from your webhost. I'd advise you to contact your webhost and check whether they have indeed got allow_url_fopen turned off.
lonesomeday
Okay, I will contact them, Thanks for the help.
Shrikrishna Meena
A: 

SimpleXML is new in PHP 5. I think almost all webhosts have PHP 5 installed, but in case your host is still using PHP 4 that may be the reason your script isn't working.

matsolof