PHP-“标头已发送"错误取决于输出长度?

PHP- quot;headers already sentquot; error depending on output length?(PHP-“标头已发送错误取决于输出长度?)
本文介绍了PHP-“标头已发送"错误取决于输出长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输出 mysql 单元数据的脚本.内容"单元格包含长度不同的文本输出.

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.

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

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 警告:无法修改标头信息 - 标头已发送通过(输出开始于/home/mantas/htdocs/asm/article.php:46)在/home/mantas/htdocs/asm/include/comments_class.php 第 56 行

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 会缓冲输出.您可以使用 ob_start() 等以编程方式对此进行控制.但是,还有一个选项可以在 php.ini 中设置输出缓冲.

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.

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

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.

PHP 参考是这里

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)