Php 检查是否打开流失败

Php 检查是否打开流失败,php,Php,我有一段代码,如下所示: if(strpos(strtolower($preview_url),"https://play.google.com/")!==false) { $dom = new DOMDocument; libxml_use_internal_errors(true); $dom->loadHTMLFile($preview_url);

我有一段代码,如下所示:

if(strpos(strtolower($preview_url),"https://play.google.com/")!==false)
            {
                $dom = new DOMDocument;
                libxml_use_internal_errors(true);
                $dom->loadHTMLFile($preview_url);
                libxml_clear_errors();
                $xp = new DOMXPath($dom);
                $image_src = $xp->query("//*[@class='cover-image']");
                $cover_image_src = $image_src->item(0)->getAttribute('src');
                echo $cover_image_src."-- ID --".$id."\n";
                $update_offer_sql = "UPDATE aw_offers_v2 SET 
                        name = '$name', description = '$description', 
                        payout_type = '$payout_type', payout = '$payout',
                        expiration_date = '$expiration_time', 
                        preview_url = '$preview_url',tracking_url = '$tracking_url', 
                        categories = '$categories', countries = '$countries',
                        countries_short = '$countries_short', 
                        update_date = '$update_time', api_key = '$api',
                        network_id = '$api_url',
                        icon = '".mysql_real_escape_string(file_get_contents($cover_image_src))."'
                        WHERE id = '$id'";
            }
但有时,如果$preview\uURL是这样一个不存在的url,那么我会

DOMDocument::loadHTMLFile(https://play.google.com/store/apps/details?id=com.mobogenie.markets): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
如何在那里显示自定义消息,而不是使用php检查和发送消息 发件人:

检查给定的url是否正常 使用:

$file_headers = @get_headers($preview_url);
if($file_headers[0] == 'HTTP/1.1 404 Not Found' || $file_headers[0] == 'HTTP/1.0 404 Not Found') {
    $exists = false;
}
else {
    $exists = true;
}
if (filter_var($preview_url, FILTER_VALIDATE_URL) === false){
  echo "There is an error :(";
}