How can I tell PHP to dump exceptions as raw text instead of HTML?

后端 未结 3 569
陌清茗
陌清茗 2020-12-11 03:38

When I\'m developing my REST API in PHP I\'m working with application/json output, so when I get errors while testing in the browser they look like this:

<
相关标签:
3条回答
  • 2020-12-11 04:03

    In your php.ini you can set three different settings to change how HTML errors are displayed.

    • html_errors
    • error_prepend_string String to output before an error message
    • error_append_string String to output after an error message

    I use the following in my development environment:

    html_errors = On
    error_prepend_string = "<pre>"
    error_append_string = "</pre>"
    
    0 讨论(0)
  • 2020-12-11 04:10

    It is a php.ini setting called html_errors.

    0 讨论(0)
  • 2020-12-11 04:14

    There may be some configuration option that I can't find to do this - I suspect there is, since the HTML is not present on the command line.

    A dirty work around is to pass the strings through html_entity_decode(strip_tags($str)).

    EDIT As Andy Pieters has pointed out (he is obviously better at reading docs than I am) there is a configuration option called html_errors to control this. I will leave this answer here in case for some reason you cannot modify this, but you should probably accept his answer.

    0 讨论(0)
提交回复
热议问题