以下动态生成 rss 提要的代码块示例无法正确打印日期。
<?php $db = new mysqli("a", "b", "c", "d");
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="http://site.com/rssfeed/" rel="self" type="application/rss+xml" />
<title>Test</title>
<description>Test Feed</description>
<link>http://site.com/rssfeed/</link>
<copyright>Your Copyright Information</copyright>
<?php $query = "SELECT * FROM `table` ORDER BY `id` DESC";
$results = $db->query($query) or die(mysql_error());
$number = $results->num_rows;
for ($i = 1; $i <= $number; $i++) {
$row = $results->fetch_assoc();
$title = $row['title'];
$description = $row['description'];
$link = $row['link'];
$date = date("r", $row['date']);
?>
<item>
<title><?php echo $title; ?></title>
<description><?php echo $description; ?></description>
<link><?php echo $link; ?></link>
<pubDate><?php echo $date; ?></pubDate>
<?php /*?><guid><?php echo $link; ?></guid><?php */?>
</item>
<?php } ?>
</channel>
</rss>
<?php $db->close(); ?>
列table
是id
, title
, description
, link
,date
当以以下方式插入值时, http://site.com/rssfeed/index.php根本不提供在<pubDate><?php echo $date; ?></pubDate>
标签内调用的任何日期输出date
INSERT INTO `table` (`id`, `title`, `description`, `link`, `date`)
VALUES
(1,'Site || Home', 'http://www.site.com', 'http://www.site.com', 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP');
另一方面,当以date
下列方式插入值时,http: //site.com/rssfeed/index.php 会向所有可用的动态提要打印错误的日期(它只为所有可用的提要打印一个错误的日期),这是什么喜欢Thursday, January 01, 1970 6:33 AM
INSERT INTO `table` (`id`, `title`, `description`, `link`, `date`)
VALUES
(1,'Site || Home', 'http://www.site.com', 'http://www.site.com', '2012-05-07 02:16:46');
顺便说一句,在 create table 语句中,列date
定义如下:
`date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Rss 验证器在验证过程中给出以下建议
Implausible date: Thu, 01 Jan 1970 01:33:32 +0100
为什么会这样?任何想法?
提前致谢。