繁体   English   中英

Apache / PHP提供错误的内容类型

[英]Apache / PHP is serving the wrong content type

我有这个PHP文件:

<?php
header('Content-type: text/xml; charset=UTF-8');
?><?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs title="hello world example" /> 
  <Content type="html">
     <![CDATA[ 
       Hello, world!
     ]]>
  </Content> 
</Module>

我希望它返回Content-type:text/xml标头。

但是,它要做的是返回Content-Type:text/html

您可以在这里查看结果: http : //knox.orgapage.de/hello.php

如果我将文件扩展名更改为.xml(当然没有PHP标记),则一切正常。 但是我想用PHP动态生成内容。

有什么建议如何解决这个问题? 如何让浏览器知道它将内容解释为XML?

它也不会输出任何文本。
我认为这是因为PHP方面的某些错误
您必须参考错误日志并修复该错误。

是的就是这样

<?php
header('Content-type: text/xml; charset=UTF-8');
echo '<?xml version="1.0" encoding="UTF-8" ?>';
?>

<Module>
  <ModulePrefs title="hello world example" /> 
  <Content type="html">
     <![CDATA[ 
       Hello, world!
     ]]>
  </Content> 
</Module>

会解决你的问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM