Is it possible to do some sort of try catch that will catch warnings?
e.g.
if (!$dom->loadHTMLFile($url)) {
//if cant load file handle error my way
}
For the $url I am using I am getting
Warning (2): DOMDocument::loadHTMLFile(MYURL) [domdocument.loadhtmlfile]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
[APP\controllers\import_controller.php, line 62]Warning (2): DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: I/O warning : failed to load external entity “hMYURL” [APP\controllers\import_controller.php, line 62]
I could just suppress the error with @, and do something if the call returns false, but I want to be able to catch the exact warning message and then do something with it.
Is this possible?
You should use
libxml_use_internal_errorsfor this.This example is adapted from the manual:
No PHP notices will be emitted here.