我有一个RSS feed,我的iTunes链接到这个feed,用于播客(所有这些功能都有效)。但是,我正在尝试对其进行设置,以便不必将每个播客数据硬编码到RSS提要中。因此,我的方法是使用podcast上传表单,它将所有数据加载到mysql数据库中,然后使用php中的"for“循环将数据读出到提要中。从表单中获取数据到数据库中的工作非常完美,连接和从数据库读取数据也是如此。但是,当我尝试将其实现到RSS提要中时,没有出现“文章”。以下是.rss文件的代码:
<?xml version="1.0" encoding="UTF-8" ?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>Victory Central Church Message Podcast</title>
<link>http://www.vc2online.com</link>
<language>en-us</language>
<copyright>℗ & © 2012 Waller Hill Publishing</copyright>
<itunes:subtitle>Victory Central Church Podcast</itunes:subtitle>
<itunes:author>Victory Central Church</itunes:author>
<itunes:summary>The Sermons from Victory Central Church - A regional church sharing the life-giving message of Jesus Christ with Central Georgia and the world!</itunes:summary>
<description>The Sermons from Victory Central Church - A regional church sharing the life-giving message of Jesus Christ with Central Georgia and the world!</description>
<itunes:owner>
<itunes:name>Victory Central Church</itunes:name>
</itunes:owner>
<itunes:image href="images/podcasts_logo.jpg" />
<itunes:category text="Christianity">
<itunes:category text="Spirituality"/>
</itunes:category>
<?php
$host = 'xxx.xx.xxx.xxx';
$username = 'xxxx';
$password = 'xxxx';
$database = 'xxxx';
mysql_connect($host, $username, $password) or die( "Unable to connect.");
@mysql_select_db($database) or die( "Unable to select database.");
$result = mysql_query("SELECT * FROM `podcasts` WHERE 1 LIMIT 0 , 30");
while ($row = mysql_fetch_array($result))
{
echo "<item>";
echo "<title>" . $row['title'] . "</title>";
echo "<itunes:author>" . $row['author'] . "</itunes:author>";
echo "<itunes:subtitle>" . $row['subtitle'] . "</itunes:subtitle>";
echo "<itunes:summary>" . $row['summary'] . "</itunes:summary>";
echo "<itunes:image href=\"" . $row['imageurl'] . "\" />";
echo "<enclosure url=\"" . $row['url'] . "\" type=\"" . $row['type'] . "\" />";
echo "<guid>" . $row['guid'] . "</guid>";
echo "<pubDate>" . $row['date'] . "</pubDate>";
echo "<itunes:duration>" . $row['duration'] . "</itunes:duration>";
echo "<itunes:keywords>" . $row['keywords'] . "</itunes:keywords>";
echo "</item><br><p />";
}
?>
</channel>
</rss>当然,主机、用户、密码和数据库都包含在实际代码中。当我按原样运行这段代码时,没有显示任何错误。只有“文章”不会出现。任何帮助都将不胜感激。谢谢!
发布于 2018-05-02 15:16:40
为此,我创建了一个小型开源库。
你可以下载并学习如何使用here,不过还是让我来举个例子:
use iTunesPodcastFeed\Channel;
use iTunesPodcastFeed\FeedGenerator;
use iTunesPodcastFeed\Item;
require __DIR__ . '/vendor/autoload.php';
// SETUP CHANNEL
$title = 'Read2Me Daily Curated Articles';
$link = 'https://read2me.online';
$author = 'NYTimes and Medium';
$email = 'hello@read2me.online';
$image = 'https://d22fip447qchhd.cloudfront.net/api/widget/static/images/default-thumbnail.png';
$explicit = false;
$categories = [
'News',
'Technology',
'Culture',
'Entrepreneurship',
'Productivity'
];
$description = 'Daily curated articles from New York Times and Medium';
$lang = 'en';
$copyright = 'The New York Times Company and The Medium Company';
$ttl = 43200; // 12 hours in seconds
$channel = new Channel(
$title, $link, $author, $email,
$image, $explicit, $categories,
$description, $lang, $copyright, $ttl
);
// SETUP EPISODE
$title = "Trump Says Disclosure of Mueller Questions in Russia Probe Is ‘Disgraceful’";
$fileUrl = 'https://s3.read2me.online/audio/www-nytimes-com-2018-05-01-us-politics-trump-mueller-russia-questions-html-7e9601.mp3';
$duration = '2:18';
$description = 'WASHINGTON — President Trump on Tuesday said it was “disgraceful” that questions the special counsel would like to ask him were publicly disclosed, and he incorrectly noted that there were no questions about collusion. The president also said collusion was a “phony” crime.';
$date = 1525177808;
$filesize = 828387;
$mime = 'audio/mpeg';
$item = new Item(
$title, $fileUrl, $duration,
$description, $date, $filesize, $mime
);
$item2 = clone $item; // just to give you an idea of how it works
// SETUP FEED
$feed = new FeedGenerator($channel, ...[$item, $item2]);
// OUTPUT XML
header('Content-Type: application/xml; charset=utf-8');
print $feed->getXml();https://stackoverflow.com/questions/9165395
复制相似问题