Is there anyway to make simpleXML work on web host
<?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_co开发者_C百科ntents(), simplexml_load_file() failed to fetch data from xml file(ex. rss files) stored on another server.
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
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.
精彩评论