How can I handle the warning of file get contents function in PHP

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I wrote a PHP code like this

$site="http://www.google.com";
$content = file_get_content($site);
echo $content;

But when I remove "http://" from $site I get the following warning:

Warning: file_get_contents(www.google.com) [function.file-get-contents]: failed to open stream:

I tried try and catch but it didn t work.

Answers

Step 1: check the return code: if($content === FALSE) { // handle error here... }

Step 2: suppress the warning by putting an @ in front of the file_get_contents: $content = @file_get_contents($site);

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/272361/how-can-i-handle-the-warning-of-file-get-contents-function-in-php

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils