如何在返回给用户之前处理所有php数据


How do I process all php data before returning to the user?

我使用zend框架,并在其上启用了布局。有时,一些编码不良的控制器/动作可能会抛出错误/警告,例如:"警告:/path/to/controllers/controllername.php中第12行有错误"。我想知道是否有一个输出点将数据返回给请求者,以便我可以在发送之前检查正在发送的内容。这样,我就可以使用正则表达式并从发送给请求者的最终结果中删除php警告。

当生成一个ZF项目时,它会创建一个错误控制器,然后设置为在任何异常未被捕获时使用。该控制器还有一个附加视图,您可以在其中指定发生错误时希望显示的内容。

我不确定是否它的设置使用控制器或如果框架使用它,如果它存在,但可能是在文档中。http://framework.zend.com/manual/en/zend.controller.exceptions.html zend.controller.exceptions.handling

与其尝试重新解析输出,不如关闭输出的错误记录和/或更改错误报告级别。

你可以直接修改php.ini或者使用ini_set方法。

error_reporting( 0 ); // Reporting is off 
error_reporting( E_ALL ); // Reports all
error_reporting( E_ERROR ); // Reports only errors
error_reporting( E_ERROR | E_WARNING ); // Reports errors and warnings
ini_set("error_reporting", E_ALL ); // Reporting is on
ini_set("error_reporting", 0 ); // Reporting is off
ini_set("display_errors", 0); // Turn off logging to output
ini_set("log_errors", 1); // Turn on logging to file
ini_set("error_log", "errors.log" ); // Name of error log