【发布时间】:2012-02-12 06:51:12
【问题描述】:
我没有包含我的网站 url,它是一个 vbulletin 论坛,所有 rss/xml 选项都已启用。 (反正我知道)
<?php
// this is the url of the rss feed that you want to display
$feed = curl_init('http://myvbforum.com/external.php?type=rss2&forumid=33');
curl_setopt($feed, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($feed, CURLOPT_HEADER, 0);
$xml = simplexml_load_file($feed);
curl_close($feed);
//if the feed exists, then continue...
if ($xml!=''){
foreach ($xml->channel->item as $item){
// create variables from the title and description (can also be used for images and links)
$title = $item->title;
$description = $item->description;
$date = $item->pubDate;
$user = $item->dc:creator;
// displays the title and description on your website, formatted any way you want
echo '<p><b>'.$title.'</b> - On '.$date.' by '.$user.' <br />'.$description.'</p>';
}}
?>
这是我正在使用的代码。我以前没有日期,但我通过我论坛上的 rss2 提要弄清楚了这一点。但是,我无法弄清楚如何让帖子的作者出现。当我查看 rss2 页面时,我能找到的唯一对作者的引用是 dc:creator 变量。我尝试将其添加到我的代码中。但是我一直得到一个
解析错误:语法错误,第 16 行 /public_html/bfdm/1/rss.php 中的意外 ':'
它显然不喜欢 :.
我尝试过使用 DOM 加载 ( $xml = new DOMDocument(); $xml->加载($feed); ) 但两者都不起作用。
基本上我只想从我的 Vbulletin 帖子中提取主题、日期、用户和线程内容。这几天让我发疯。
现在我突然变了
警告:simplexml_load_file() 期望参数 1 是字符串,资源在 /public_html/bfdm/1/rss.php 第 6 行给出
在上面的代码中用
【问题讨论】: