【发布时间】:2010-09-19 16:01:49
【问题描述】:
<?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;
?>
我使用此代码获取推文,它在 localhost 上成功运行,但在我的虚拟主机上无法运行,我在两个虚拟主机服务上尝试了此脚本。
我注意到的问题是 file_get_contents()、simplexml_load_file() 等函数无法从存储在另一台服务器上的 xml 文件(例如 rss 文件)中获取数据。
【问题讨论】:
-
看起来像是托管服务器上的某种配置问题。访问与文件操作相关的方法可能存在某种限制。
-
你得到的确切错误是什么?
-
虚拟主机上的空白网页,但本地主机成功检索推文。
标签: php simplexml file-get-contents