VBulletin RSS подача на основной сайт
Я не включил 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. Который я пытался добавить в свой код. Однако я продолжаю получать
Ошибка разбора: синтаксическая ошибка, неожиданное ':' в /public_html/bfdm/1/rss.php в строке 16
Это, видимо, не нравится.
Я пытался использовать загрузку DOM ( $xml = new DOMDocument(); $xml->load($feed);), но ни одна из них не работает.
По сути, я просто хочу извлечь тему, дату, пользователя и содержание темы из моих сообщений Vbulletin. Это сводило меня с ума в течение нескольких дней.
Теперь вдруг я получаю
Предупреждение: simplexml_load_file() ожидает, что параметр 1 будет строкой, ресурс указан в /public_html/bfdm/1/rss.php в строке 6
В коде выше с
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>';
}}
?>