PHP simple HTML DOM parser errors when crawling some Web pages


I could some Web pages with the ingenious tool PHP simple HTML DOM parser not crawl, the content, the method file_get_contents() false back delivered.

To fix the error, was it only necessary, the function call to replace:

$html = file_get_html($myUrl);

the function and the use of curl with a correct USER_AGENT header:

$html = getHtml($myUrl);
   function getHtml($url)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        $str = curl_exec($curl);
        curl_close($curl);

        $html = str_get_html($str);
        return $html;
    }

Curl is to still more efficient than file_get_contents().

If other errors or problems the very good worth FAQ page of the project.