php - How to skip code when file_get_contents fails? -


when use valid url following, file_get_contents return html code

$html = file_get_contents("http://www.google.com/"); 

but if url invalid:

$html = file_get_contents("http://www.go1235ogle.com/"); //invalid url. line give error message 

my code output error message notice: trying property of non-object

if file_get_contents can't open given url, want hide error message it's outputting , skip code bellow if else statement.

if (false === $html)  {   //skip code in here ? } 

but code above doesn't help. can please tell me how can correct problem?

if (false === $html)  {   // todo: handle case when file_get_contents fails } else {   // todo: handle case when file_get_contents succeeds } 

to rid of notice: trying property of non-object, either turn off outputting error messages turning display_errors off (recommended in production environment), or set error_reporting lower level.

however, code posted should not produce notice: trying property of non-object.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -