我的应用程序中有以下 PHP 代码
ob_start();
require_once($reportTemplate);
if ( ob_get_length() > 0 ) {
$reportHtml = ob_get_contents();
}
ob_end_clean();
return $returnHtml;
上面的代码负责生成 html,有时对于相同的输入,代码会为 $returnHtml 返回空值。
同样的原因可能是什么?
$returnHtml 应始终包含一些 Html 代码。
您正在
$reportHtml
中定义变量 $reportHtml = ob_get_contents();
,然后返回不同的变量 $returnHtml
。
看起来这是一个错字,相反你应该这样做:
return $reportHtml;