Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
设置从mysql数据库(使用php)读取信息的RSS提要(用于iTunes播客)_Php_Rss_Itunes - Fatal编程技术网

设置从mysql数据库(使用php)读取信息的RSS提要(用于iTunes播客)

设置从mysql数据库(使用php)读取信息的RSS提要(用于iTunes播客),php,rss,itunes,Php,Rss,Itunes,我有一个RSS源,我把iTunes链接到它上面,用来播客所有这些作品。然而,我正在尝试设置它,这样我就不必将每个播客数据硬编码到RSS提要中。因此,我的方法是使用一个podcast上传表单,将所有数据加载到一个mysql数据库中,然后使用php中的for循环将其读取到提要中。将表单中的数据输入数据库非常有效,连接和读取数据库也很有效。然而,当我尝试在RSS提要中实现这一点时,没有出现任何文章。以下是.rss文件的代码: <?xml version="1.0" encoding="UTF-8

我有一个RSS源,我把iTunes链接到它上面,用来播客所有这些作品。然而,我正在尝试设置它,这样我就不必将每个播客数据硬编码到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>&#x2117; &amp; &#xA9; 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>

当然,主机、用户、密码和数据库都包含在实际代码中。按原样运行此代码时,不会显示任何错误。只有没有文章出现。任何帮助都将不胜感激。谢谢

我为此创建了一个小型开源库

您可以下载并学习如何使用它,但让我举个例子:

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();

我已经为此创建了一个小型开源库

您可以下载并学习如何使用它,但让我举个例子:

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();

您确保Web服务器将.rss文件视为包含将被解析和执行的PHP代码的文件?对不起,我不完全确定您的意思。通常,Web服务器的配置是,只有以.PHP结尾的文件才会通过PHP解析器推送。您提到您的文件以.rss结尾。你确定你的web服务器评估了文件中的PHP脚本吗?如果是,那么检查你的PHP错误日志。好吧,我尝试了3种方式重写文件,使用了.PHP、.rss和.xml,并使用了适当的编码,但没有一种有效。如果服务器不允许这样做,.php也不会写rss吗?您确保您的Web服务器将您的.rss文件视为包含将被解析和执行的php代码的文件吗?对不起,我不完全明白你的意思。通常,Web服务器的配置是,只有以.php结尾的文件才能通过php解析器。您提到您的文件以.rss结尾。你确定你的web服务器评估了文件中的PHP脚本吗?如果是,那么检查你的PHP错误日志。好吧,我尝试了3种方式重写文件,使用了.PHP、.rss和.xml,并使用了适当的编码,但没有一种有效。如果服务器不允许,那么.php也不会写rss吗?