我正在尝试阅读一个简单的 Twitpic rss 提要,但运气不佳。我看不出我的代码有什么问题,但它只在使用 print_r() 时返回以下内容
Array ( [title] => SimpleXMLElement Object ( ) )
这是我的代码:
function get_twitpics() {
/* get raw feed */
$url = 'http://www.twitpic.com/photos/Shealan/feed.rss';
$raw = file_get_contents($url);
$xml = new SimpleXmlElement($raw);
/* create array from feed items */
foreach($xml->channel->item as $item) {
$article = array();
$article['title'] = $item->description;
}
return $article;
}
最佳答案
foreach($xml->channel->item as $item) {
$article = array(); // so you want to erase the contents of $article with each iteration, eh?
$article['title'] = $item->description;
}
如果您不仅仅对最后一个元素感兴趣,您可能需要查看您的 for 循环 - 即
$article = array();
foreach($xml->channel->item as $item) {
$article[]['title'] = $item->description;
}
关于php - 使用 SimpleXML 读取 RSS 提要时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3908590/