VBulletin RSS提要到主网站

时间:2012-02-12 06:51:13

标签: php rss vbulletin

我没有包含我的网站网址,它是一个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-&GT;负载($饲料); )但都不起作用。

基本上我只想从我的Vbulletin帖子中提取主题,日期,用户和帖子内容。它让我疯狂了好几天。

现在我突然得到了

警告:simplexml_load_file()期望参数1为字符串,资源在第6行的/public_html/bfdm/1/rss.php中给出

使用

编写上面的代码

1 个答案:

答案 0 :(得分:1)

这应该有用(或至少在有-时工作):

$user = $item->{'dc:creator'};

同样必须使用名称中的其他特殊字符,例如-

编辑:不是这种情况。但是,最终的工作代码应该是:

<?php
// this is the url of the rss feed that you want to display
$feed = 'URL OF THE RSS'; //replace this with the RSS's URL
$xml = simplexml_load_file($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->children('dc', true)->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>';
}}
?>