Php 使chrome显示rss提要(2)
这个问题是这个问题的后续: 我从这个页面复制了源代码(希望这对网站所有者来说没问题):Php 使chrome显示rss提要(2),php,xml,google-chrome,rss,Php,Xml,Google Chrome,Rss,这个问题是这个问题的后续: 我从这个页面复制了源代码(希望这对网站所有者来说没问题): . 我转义了所有的引号,并用它制作了一个php文件。该文件如下所示: <?php header('Content-Type: application/rss+xml'); echo "<?xml version=\"1.0\" ?> <?xml-stylesheet type=\"text/css\" href=\"http://www.petefreitag.com/rss/s
.
我转义了所有的引号,并用它制作了一个php文件。该文件如下所示:
<?php
header('Content-Type: application/rss+xml');
echo "<?xml version=\"1.0\" ?>
<?xml-stylesheet type=\"text/css\" href=\"http://www.petefreitag.com/rss/simple_style.css\" ?>
<rss version=\"2.0\">
<channel>
<title>Pete Freitag's Homepage</title>
<link>http://www.petefreitag.com/</link>
<description>Covering ColdFusion, Java, Web Development, and other topics</description>
<language>en-us</language>
<lastBuildDate>Fri, 23 Mar 2012 18:57:00 GMT</lastBuildDate>
<ttl>45</ttl>
<item>
REST OF THE SOURCE CODE
</rss>
";
?>
在这里您可以看到结果:
然而,在chrome上,它以rss提要的形式查看页面,在我的示例中,它只显示源代码
区别是什么?我如何强制chrome以rss提要的形式查看页面?添加doctype
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
尝试将标题更改为
application/xml
这通过更改标题对我有效:
<?php
header('Content-Type: application/xml');
echo file_get_contents('http://web.student.tuwien.ac.at/~e0250890/rsstest/test.php');
?>
Mozilla接受一系列的头文件
text/xml
,application/xml
,application/rss+xml
,application/atom+xml
但chrome似乎只接受text/xml
或application/xml
不是100%确定为什么,也许你应该与谷歌合作;p'application/xml'可以工作,但是'application/rss+xml'不也应该工作吗?第二个不是正确的mime类型吗?您可以通过打开一个新版本来请求Chrome更改其行为:此doctype描述html文档,而不是rss提要