我正在尝试使用 simpleXML 提要从 rss 提要中获取图像,并通过数组解析数据并返回到 foreach 循环中......
在源代码中,[description] 的数组显示为空白,尽管我已经设法使用另一个循环将其拉出,但是,我终生无法弄清楚如何拉入下一个数组,随后每个帖子的图像!
帮助?
你可以在这里查看我的进度:http: //dev.thebarnagency.co.uk/tfolphp.php
这是原始提要: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;`
}
}
谢谢