如何解决PHP RSS 提要帮助获取要显示的 XML 标签
我正在使用以下代码为我的网站生成 RSS 提要。运行代码时,出现错误:Error on line 1 at column 14: XML declaration allowed only at the start of the document
。如果我取出 header(),页面会运行,但数据格式不正确,包括整个数据数组。当我从我的 WordPress 站点请求 RSS 提要时,我得到了格式正确的 XML 响应。对我缺少的东西有什么想法吗?
谢谢,
达雷尔
代码:
if($result){
//header( "Content-type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0'>
<channel>
<title>Mom Minder | RSS</title>
<link>www.darrellh89.com</link>
<description>Mom Minder Notes</description>
<language>en-us</language>";
while($row = mysqli_fetch_array($result)){
//print_r($row);
$rssTitle=$row["Title"];
$rssNote=$row["Note"];
$rssDate=$row["postDate"];
$rssTime=$row["postTime"];
echo "<item>
<title>$rssTitle</title>
<note>$rssNote</note>
<postdate>$rssDate</postdate>
<posttime>$rssTime</posttime>
</item>";
}
echo "</channel></rss>";
}
错误响应:源代码看起来正确,带有...
www.darrellh89.com Mom Minder Notes en-us Did you brush your teeth? 2020-12-21 08:30:00 What restaurant do you want to eat at? 2020-12-21 04:56:05 I'll pick you up at 5 2020-12-21 04:56:05 I'll pick you up at 4PM on Wednesday for the foot doctor 2020-12-22 04:56:05 Did you eat all your eggs? 2021-01-03 12:06:00
我想要的
<channel>
<title>Adventure Scuba</title>
<atom:link href="https://ohioadventurescuba.com/feed/" rel="self" type="application/rss+xml" />
<link>https://ohioadventurescuba.com</link>
<description>Individual Instruction on Your Schedule</description>
<lastBuildDate>Sun,20 Dec 2020 15:37:02 +0000</lastBuildDate>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。