PHP-“头部已经发送”取决于输出长度的错误? [英] PHP- "headers already sent" error depending on output length?

查看:172
本文介绍了PHP-“头部已经发送”取决于输出长度的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输出mysql单元格数据的脚本。 content单元格包含文本输出,其长度各不相同。

当content单元格的内容很小时(可以说,几行文本),一切正常。
但是,当输出达到几个段落或更多时,我会收到'headers already sent'错误。

它取决于输出长度吗?我在哪里可以阅读更多关于它的内容我在SO上找到的答案没有提及这种输出长度依赖性。

  44:echo
45 :< p>。$ article ['content']。< / p>
46:;

如果'content'输出的大小很大,脚本会产生以下错误:


PHP警告:无法修改标头信息 - 标头已经发送了
by(输出开始于/ home / mantas / htdocs / asm / article .php:46)in
/home/mantas/htdocs/asm/include/comments_class.php on line 56



解决方案

如果你愿意,PHP会缓冲输出。你可以用 ob_start()等来编程控制它。但是,还有一个选项可以在php.ini中设置输出缓冲。

设置 output_buffering = on 启用它,同时设置 output_buffering = 4096 将设置缓冲区大小的限制。 phpinfo()应该告诉你这是否启用,以及缓冲区大小是多少。

PHP引用是此处


I have a script which outputs mysql cell data. The "content" cell contains text output, which is of varied length.

When the contents of the "content" cell are small (lets say, a few lines of text), everything works fine. However, when the output reaches several paragraphs or more, I get the 'headers already sent' error.

Does it depend on the output length? Where can I read more about it? The answers I've found on SO mention nothing of such output length-dependency.

 44:   echo "
 45:       <p>".$article['content']."</p>
 46:   ";

If the size of the 'content' output is large, the script produces the following error:

PHP Warning: Cannot modify header information - headers already sent by (output started at /home/mantas/htdocs/asm/article.php:46) in /home/mantas/htdocs/asm/include/comments_class.php on line 56

解决方案

PHP will buffer output if you want it to. You can control this programmatically with ob_start(), etc. However, there is a further option to set output buffering on in php.ini.

Setting output_buffering=on enables it, while setting output_buffering=4096 will set a limit to the buffer size. phpinfo() should tell you if this is enabled, and what the buffer size is.

The PHP reference is here

这篇关于PHP-“头部已经发送”取决于输出长度的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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