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

2023-11-30php开发问题
5

本文介绍了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-“标头已发送"错误取决于输出长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17