Try adding try-catchto this function:
try{
$dom->load(call_user_func_array('file_get_contents', $args), true);
return $dom;
}
catch(Exception $e){
throw new Exception('could not load the url');
}
Strike>
Update:
Or you can use this function to see if the remote link really exists:
function url_exists($url){
if ((strpos($url, "http")) === false) $url = "http://" . $url;
if (is_array(@get_headers($url)))
return true;
else
return false;
}
Here is how you can use the above function:
function file_get_html() {
$args = func_get_args();
if (url_exists($args)) {
$dom = new simple_html_dom;
$dom->load(call_user_func_array('file_get_contents', $args), true);
return $dom;
}
else {
echo "The url isn't valid";
return false;
}
}
source
share