PHP DOMDocument error handling

前端 未结 5 1670
予麋鹿
予麋鹿 2020-12-03 05:01

In my application I am loading xml from url in order to parse it. But sometimes this url may not be valid. In this case I need to handle errors. I have the following code:

5条回答
  •  猫巷女王i
    2020-12-03 05:30

    To disable throwing errors:

    $internal_errors = libxml_use_internal_errors(true);
    
    $dom = new DOMDocument();
    // etc...
    
    libxml_use_internal_errors($internal_errors);
    

提交回复
热议问题