Apache或者PHP发电prepending换行符 [英] Apache or PHP generating prepending line feed character

查看:166
本文介绍了Apache或者PHP发电prepending换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想产生一个PHP Web应用程序的XML文件:

I am trying to generate an XML file in a PHP web application:

<?php
... 
header('Content-Type: application/xml');
header('Content-Disposition: attachment; filename=test.xml');
echo "<?xml version=\"1.0\"?>\r\n" . 
...

奇怪的是,用我的服务器时(PHP 5.3.8版本/ 2.2.17的Apache和PHP版本5.3.10-1 /阿帕奇2.2.22分别)换行符(十六进制 0A )字符被插入在输出的开始,导致不能使用无效的XML。有<一个href=\"http://askubuntu.com/questions/175870/apache-or-php-inserting-a-newline-at-start-of-every-html-and-xhr-response\">one这个,未解决的更多的在线提问。

Bizarrely, when using my servers (PHP Version 5.3.8/Apache 2.2.17 and PHP Version 5.3.10-1/Apache 2.2.22 respectively) a line feed (hex 0a) character is inserted in the beginning of the output, resulting in invalid XML that cannot be used. There's one more online question about this, unresolved.

所以,如果我尝试回声错误; 我得到的4个字节,而不是3: 0A 62 75 67

So if I try echo "bug"; I get 4 bytes, not 3: 0a 62 75 67

但是,使用本地WAMP服务器时(PHP 5.4.3 / 2.4.2的Apache),我得到3个字节: 62 75 67

However, when using WAMP server locally (PHP 5.4.3/Apache 2.4.2), I get 3 bytes: 62 75 67.


  • 这是一个已知的bug /功能吗?

  • 它是一个配置问题?

  • 这是难辞其咎的,Apache或
    PHP?

  • 请我一定要升级我的服务器?我宁愿不要。

推荐答案

这似乎是 0A 问题由尾随造成由包括一个PHP文件中输入字符我主要的PHP文件。当我从包含文件中删除它,在我的输出 0A 字符消失。

It seems like the 0a problem was caused by a trailing Enter character in a PHP file included by my main PHP file. When I removed it from the include file, the 0a character in my output disappeared.

我发现特别之处,这是不同的处理,我经历了PHP版本之间的空白,而事实上测试社区的建议时,我还是得到了 0A

What I find peculiar about this is the different handling of whitespace between PHP versions that I experienced, and the fact that I still got the 0a when testing the community's suggestions.

我没有更多的时间投入研究这个,但我的建议的人遇到类似的问题是检查中的空白是否包含文件可能发挥到方程。此外,应避免结束&LT;?PHP 由丹建议标签下方

I have no more time to put research into this, but my advice to people experiencing similar problems is to check whether whitespace in include files may play into the equation. In addition, avoid ending the <?php tag as suggested by Dan below.

这篇关于Apache或者PHP发电prepending换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆