PHP handle errors

后端 未结 2 1667
迷失自我
迷失自我 2021-01-14 04:56

Using this code with simplehtmldom script (http://simplehtmldom.sourceforge.net/manual.htm):

function file_get_html() {
    $dom = new simple_html_dom;
    $         


        
2条回答
  •  无人及你
    2021-01-14 04:58

    Hi You need to check for the 404 Not Found message as there is returned an array in any case.

    function url_exists($url){
    if ((strpos($url, "http")) === false) $url = "http://" . $url;
    $headers = @get_headers($url);
    //print_r($headers);
    if (is_array($headers)){
        //Check for http error here....should add checks for other errors too...
        if(strpos($headers[0], '404 Not Found'))
            return false;
        else
            return true;    
    }         
    else
        return false;
    }
    

提交回复
热议问题