php - Check for failed to open stream -



php - Check for failed to open stream -

i have piece of code given below:

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))."' id = '$id'"; }

but sometimes, if $preview_url such url doesnt exist, getting

domdocument::loadhtmlfile(https://play.google.com/store/apps/details?id=com.mobogenie.markets): failed open stream: http request failed! http/1.0 404 not found

how can show custom message on there bu checking , throing message using php

check if it's 404

from here:

$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; } check if given url ok

use filter_var:

if (filter_var($preview_url, filter_validate_url) === false){ echo "there error :("; }

php

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -