doujiao1538 2012-09-13 22:52
浏览 39

显示空白数组的SimpleXML提要 - 如何获取内容?

I'm trying to get the image out of a rss feed using a simpleXML feed and parsing the data out via an array and back into the foreach loop...

in the source code the array for [description] is shown as blank though I've managed to pull it out using another loop, however, I can't for the life of me work out how to pull in the next array, and subsequently the image for each post!

help?

you can view my progress here: http://dev.thebarnagency.co.uk/tfolphp.php

here's the original feed: feed://feeds.feedburner.com/TheFutureOfLuxury?format=xml

$xml_feed_url = 'http://feeds.feedburner.com/TheFutureOfLuxury?format=xml';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $xml_feed_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);

function produce_XML_object_tree($raw_XML) {
libxml_use_internal_errors(true);
try {
    $xmlTree = new SimpleXMLElement($raw_XML);
} catch (Exception $e) {
    // Something went wrong.
    $error_message = 'SimpleXMLElement threw an exception.';
    foreach(libxml_get_errors() as $error_line) {
        $error_message .= "\t" . $error_line->message;
    }
    trigger_error($error_message);
    return false;
}
return $xmlTree;
}

$feed = produce_XML_object_tree($xml);

print_r($feed);

foreach ($feed->channel->item as $item) {
// $desc = $item->description;

echo '<a href="'.$item->link.'">link</a><br>';

    foreach ($item->description as $desc) {
        echo $desc;`


    } 
}

thanks

  • 写回答

2条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题