개발! 딱 깔끔하고 센스있게!

PHP 경고 잡기 시도 본문

개발 스크랩 메모/PHP

PHP 경고 잡기 시도

렉사이 2020. 12. 3. 23:54

포획 경 고 를 위해 서 모종 의 시도 가 가능 합 니까?

예컨대.

if (!$dom->loadHTMLFile($url)) { //if cant load file handle error my way } 

내 가 사용 하고 있 는 $url 에 대하 여

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] 

저 는 실 수 를 억제 하고 false 를 되 돌 릴 때 일부 조작 을 할 수 있 습 니 다.

그러나 정확 한 경고 메 시 지 를 포착 하고 이 를 실행 할 수 있 기 를 바 랍 니 다.

그게 가능 합 니까?

감사합니다.

대답 하 다.

이 를 위해 libxml use internal erros 를 사용 해 야 합 니 다.

이 예제 는 설명 페이지 에서 개편 합 니 다:

libxml_use_internal_errors(true); $doc = new DOMDocument(); $res = $doc->loadHTMLFile($url); //this may fail and return FALSE! foreach (libxml_get_errors() as $error) { // handle errors here } libxml_clear_errors(); 

이곳 에 서 는 PHP 알림 이 나 오지 않 습 니 다.

Comments