繁体   English   中英

VBulletin RSS feed到主要网站

[英]VBulletin RSS feed to main website

我没有包括我的网站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 feed可以弄清楚。 但是,我不知道如何让该帖子的作者出现。 当我查看rss2页面时,唯一可以找到的作者参考是dc:creator变量。 我尝试将其添加到代码中。 但是我不断得到

解析错误:语法错误,第16行的/public_html/bfdm/1/rss.php中出现意外的':'

它显然不喜欢:。

我试过使用DOM加载($ xml = new DOMDocument(); $ xml-> load($ feed);),但是都没有用。

基本上我只想从我的Vbulletin帖子中获取主题,日期,用户和主题内容。 几天来一直让我发疯。

现在突然之间

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

在上面的代码中

这应该有效(或至少在具有- ):

$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>';
}}
?> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM