php 谷歌浏览器将 XML 呈现为 RSS 提要的文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1656574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:24:54  来源:igfitidea点击:

Google Chrome rendering XML as text for RSS feed

phpxmlrssgoogle-chrome

提问by Scott

I have this script to generate an XML file for an RSS feed. Works great in every browser except Chrome. Chrome just renders the XML as text. Something to do with header("Content-Type: application/rss+xml; charset=ISO-8859-1");possibly?

我有这个脚本来为 RSS 提要生成一个 XML 文件。在除 Chrome 之外的所有浏览器中都能很好地工作。Chrome 只是将 XML 呈现为文本。header("Content-Type: application/rss+xml; charset=ISO-8859-1");可能跟什么有关?

This is the code I'm using:

这是我正在使用的代码:

<?php

$linkUp = "http://localhost/sites/myBlog/";

header("Content-Type: application/rss+xml; charset=ISO-8859-1");

$rssfeed  = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$rssfeed .= '<rss version="2.0">';
$rssfeed .= '<channel>';
$rssfeed .= '<title>Mytitle</title>';
$rssfeed .= '<link>' . $linkUp . '</link>';
$rssfeed .= '<description>Mydescription</description>';
$rssfeed .= '<language>en-us</language>';
$rssfeed .= '<copyright>&copy; ' . strftime('%Y') .  ' . " " . ' . $linkUp . '</copyright>';


$query = "SELECT * FROM rss";
$result = $db->query($query);

while($row = $db->fetch_array($result)) {

    $rssfeed .= '<item>';
    $rssfeed .= '<title>' . $row['rss_title'] . '</title>';
    $rssfeed .= '<description>' . $row['rss_description'] . '</description>';
    $rssfeed .= '<link>' . $row['rss_link'] . '</link>';
    $rssfeed .= '<pubDate>' . date("D, d M Y H:i:s O", strtotime($date)) . '</pubDate>';
    $rssfeed .= '</item>';
}

$rssfeed .= '</channel>';
$rssfeed .= '</rss>';

echo $rssfeed;

?>

回答by Wedge

This is a known bugin chrome that has yet to be fixed, chrome does not display xml rss feeds with any formatting whatsoever.

这是chrome 中的一个已知错误,尚未修复,chrome 不显示任何格式的 xml rss 提要。

Update: There is now an RSS subscription / reader extensionfor Chrome.

更新:现在有一个适用于 Chrome的RSS 订阅/阅读器扩展

回答by Andrew Christensen

I had this same problem and I used "application/xml" and it fixed it right up. Chrome doesn't like "application/rss+xml".

我遇到了同样的问题,我使用了“application/xml”,它立即修复了它。Chrome 不喜欢“application/rss+xml”。

回答by dmp

Bottom line, RSS support isnt used by "majority" of users, and as such they are only implementing it as an extension, for now. The extension is available here: RSS SubscriptionExtension

最重要的是,“大多数”用户并未使用 RSS 支持,因此他们目前仅将其作为扩展来实现。该扩展程序在此处可用: RSS SubscriptionExtension

There's a detailed discussion of this on the closing comment for the bug - you can read the developer notes here: Comment 149

关于该错误的结束评论对此进行了详细讨论 - 您可以在此处阅读开发人员说明: 评论 149

回答by EddieO

try the chrome extension "XML Tree"

尝试 chrome 扩展“XML 树”

回答by Traveling Tech Guy

Try changing the header to text/xmland see if it helps:

尝试将标题更改为text/xml,看看是否有帮助:

header("Content-Type: text/xml; charset=ISO-8859-1");

回答by Nicholas Petersen

Short answer: add "view-source:{feedurl}"

简短回答:添加“查看源:{feedurl}”

Note that when the url ends with .xml and is recognized as a feed by chrome, Chrome annoyingly opens a Save File dialog. But many feed urls don't end with an extension (i.e. .xml), such as:

请注意,当 url 以 .xml 结尾并被 chrome 识别为提要时,Chrome 会烦人地打开“保存文件”对话框。但是许多提要网址不以扩展名(即 .xml)结尾,例如:

http://feeds.feedburner.com/ScottHanselman

At root, that url is still a regular, xml feed, but for us coders who just want to see the real xml, Chrome and the others in this case show you a human readable display of the feed (very annoying!).

从根本上讲,该 url 仍然是一个常规的 xml 提要,但对于我们只想查看真实 xml 的编码人员来说,Chrome 和其他在这种情况下会向您显示提要的人类可读显示(非常烦人!)。

So the answer to bothof these problems is contained in the comment above given by Arne Roomann-Kurrik. He should have put it as an answer, because it works!

因此,这两个问题的答案包含在 Arne Roomann-Kurrik 给出的上述评论中。他应该把它作为答案,因为它有效!

view-source:http://feeds.feedburner.com/ScottHanselman You don't even need "http://".

查看源:http://feeds.feedburner.com/ScottHanselman 你甚至不需要“http://”。