Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何告诉PHP将异常转储为原始文本而不是HTML?_Php_Error Handling - Fatal编程技术网

如何告诉PHP将异常转储为原始文本而不是HTML?

如何告诉PHP将异常转储为原始文本而不是HTML?,php,error-handling,Php,Error Handling,当我用PHP开发REST API时,我使用的是application/jsonoutput,因此当我在浏览器中测试时出现错误时,它们看起来如下所示: <b>Fatal error</b>: Uncaught exception 'Exception' with message 'PDO caught an error: array(3) { [0]=&gt; string(5) &quot;42000&quot; [1]=&gt

当我用PHP开发REST API时,我使用的是
application/json
output,因此当我在浏览器中测试时出现错误时,它们看起来如下所示:

<b>Fatal error</b>: Uncaught exception 'Exception' with message 'PDO caught an error:
array(3) {
  [0]=&gt;
  string(5) &quot;42000&quot;
  [1]=&gt;
  int(1065)
  [2]=&gt;
  string(15) &quot;Query was empty&quot;
}
致命错误:未捕获的异常“exception”,消息为“PDO捕获错误:
阵列(3){
[0]=
串(5)“42000”
[1]=
内部(1065)
[2]=
字符串(15)“查询为空”
}

当我得到大的堆栈跟踪和其他东西时,情况会变得更糟。那么,我是否可以设置一个标志,告诉PHP我希望错误以原始文本的形式出现?

这是一个名为
PHP.ini
的设置。

可能有一些配置选项我找不到,我怀疑有,因为命令行上没有HTML

一项棘手的工作是通过
html\u entity\u decode(strip\u tags($str))
传递字符串

编辑正如Andy Pieters所指出的(他显然比我更擅长阅读文档),有一个名为“控制”的配置选项。我将把这个答案留在这里,以防由于某些原因您无法修改它,但您可能应该接受他的答案。

在php.ini中,您可以设置三种不同的设置来更改HTML错误的显示方式

  • 要在错误消息之前输出的字符串
  • 错误消息后要输出的字符串
我在我的开发环境中使用以下内容:

html_errors = On
error_prepend_string = "<pre>"
error_append_string = "</pre>"
html\u errors=On
错误_prepend_string=“”
错误\u append\u string=“”

也不要忘记设置足够的值。