PHP 输出缓冲区为相同输入返回不同(空)输出

问题描述 投票:0回答:1

我的应用程序中有以下 PHP 代码

ob_start();
require_once($reportTemplate);
 if ( ob_get_length() > 0 ) {
    $reportHtml = ob_get_contents();
}
ob_end_clean();
return $returnHtml;

上面的代码负责生成 html,有时对于相同的输入,代码会为 $returnHtml 返回空值。

同样的原因可能是什么?

$returnHtml 应始终包含一些 Html 代码。

php output-buffering
1个回答
0
投票

您正在

$reportHtml
中定义变量
$reportHtml = ob_get_contents();
,然后返回不同的变量
$returnHtml

看起来这是一个错字,相反你应该这样做:

return $reportHtml;
© www.soinside.com 2019 - 2024. All rights reserved.