【发布时间】:2010-12-01 23:00:05
【问题描述】:
您好,我一直在使用此代码在网站上显示我的状态
$doc = new DOMDocument();
# load the RSS
if($doc->load('http://twitter.com/statuses/user_timeline/12345678.rss')) {
# number of tweets to display. 20 is the maximum
$max_tweets = 3;
$i = 1;
foreach ($doc->getElementsByTagName('item') as $node) {
# fetch the title from the RSS feed.
$tweet = $node->getElementsByTagName('title')->item(0)->nodeValue;
$date = $node->getElementsByTagName('pubDate')->item(0)->nodeValue;
$link = $node->getElementsByTagName('link')->item(0)->nodeValue;
# the title of each tweet starts with "username: " which I want to remove
$tweet = substr($tweet, stripos($tweet, ':') + 1);
if(preg_match('/^\s*@([0-9a-zA-Z]+)/', $tweet))
continue;
$date = date("dS F Y", strtotime($date));
# Turn URLs into links
$tweet = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@',
'<a href="$1">$1</a>', $tweet);
# Turn @replies into links
#$tweet = preg_replace("/@([0-9a-zA-Z]+)/",
#"<a href=\"http://twitter.com/$1\">@$1</a>",
#$tweet);
# Turn & into &
$tweet = preg_replace('@&@',
'&', $tweet);
if($i%2 == 0) {
echo "<div class=\"three-col center\"><p>". $tweet . "<br /><span class=\"quiet\"><a href=\"". $link ."\">". $date ."</a></span></p></div>\n";
}
else {
echo "<div class=\"three-col\"><p>". $tweet . "<br /><span class=\"quiet\"><a href=\"". $link ."\">". $date ."</a></span></p></div>\n";
}
if($i++ >= $max_tweets) break;
}
}
直到最近它一直运行良好!这些是我看到的错误...
警告:DOMDocument::load() [domdocument.load]: php_network_getaddresses: getaddrinfo failed: 第 5 行名称解析暂时失败
警告:DOMDocument::load(http://twitter.com/statuses/user_timeline/12345678.rss) [domdocument.load]:无法打开流:php_network_getaddresses:getaddrinfo 失败:第 5 行名称解析暂时失败
警告:DOMDocument::load() [domdocument.load]: I/O 警告:未能在第 5 行加载外部实体“http://twitter.com/statuses/user_timeline/12345678.rss”
非常感谢您的想法
谢谢
【问题讨论】: