【问题标题】:VBulletin RSS feed to main website主网站的 VBulletin RSS 提要
【发布时间】: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 行给出

在上面的代码中用

【问题讨论】:

    标签: php rss vbulletin


    【解决方案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>';
    }}
    ?> 
    

    【讨论】:

    • 新问题是这个警告:simplexml_load_file() 期望参数 1 是字符串,在第 6 行的 /public_html/bfdm/1/rss.php 中给出的资源不知道为什么它突然给出(在我之前尝试使用您的建议)
    • 使用$feed = 'http://myvbforum.com/external.php?type=rss2&amp;forumid=33'; 就可以了。不需要卷曲。
    • 它给了我一些 curl 错误,但我猜这是尝试从不存在的 curl 调用的问题。但是,海报的名字仍然没有出现。这是 vbulletins RSS2 的问题吗?可以用 rss 代替吗?
    • 删除所有卷曲代码。海报的名字,我来看看。希望很快我就能说出原因。
    • 我真的很感激 :)。我一直在寻找过去 3 天。我在这里或那里找到了一些小片段,但我似乎无法拼凑起来。它可能只是 RSS2。
    猜你喜欢
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 2011-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多