<?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;
?>我使用这段代码来获取tweet,它在本地主机上运行成功,但不是在我的网站主机上,我在两个虚拟主机服务上尝试了这个脚本。
我注意到的问题是,像file_get_contents()、simplexml_load_file()这样的函数无法从xml文件中获取数据。rss文件)存储在另一服务器上。
发布于 2010-09-20 00:11:15
我相信这意味着你已经关闭了fopen URL包装器。请参阅http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen如果您使用的是共享web服务器,则可能无法打开这些服务。
您也可以使用cURL来获取远程页面:
$ch = curl_init('http://twitter.com/statuses/user_timeline/ishrikrishna.xml?count=1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$buffer = curl_exec($ch);只有在您的网站主机上安装并启用了cURL扩展,这才能起作用。
请参阅PHP文档:http://www.php.net/manual/en/book.curl.php
编辑:更正的curl_setopt调用
发布于 2010-09-23 22:10:18
SimpleXML是PHP5中的新特性,我想几乎所有的网站主机都安装了PHP5,但是如果你的主机还在使用PHP4,这可能就是你的脚本不能工作的原因。
https://stackoverflow.com/questions/3746405
复制相似问题