Page 1 of 1
validate file_get_contents
Posted: Sun Nov 19, 2006 11:54 am
by GeXus
Does anyone know how to validate file_get_contents?
Im using the following
Code: Select all
if(file_get_contents("url") !== FALSE){// do stuff}
But this does not work.. i recieve the failed to open stream error...
Re: validate file_get_contents
Posted: Sun Nov 19, 2006 12:34 pm
by volka
GeXus wrote:But this does not work.. i recieve the failed to open stream error...
And what do you expect?
Posted: Sun Nov 19, 2006 12:55 pm
by GeXus
I would expect it to do nothing.. or if i do
Code: Select all
if(file_get_contents("url") !== FALSE){echo "good";}else{echo "bad";}
Then I would expect it to display "bad", which it does not.
Posted: Sun Nov 19, 2006 1:43 pm
by John Cartwright
It works fine for me, also you may want to use @ for error supression, if you wanted to handle your own errors
Code: Select all
if(!$file = @file_get_contents("url")){
echo $file;
}else{
echo "bad";
}
Posted: Sun Nov 19, 2006 2:34 pm
by GeXus
Jcart, Yes that does work.. where FALSE does not.. thanks!
Could you explain how the @ works? Thank You.
Posted: Sun Nov 19, 2006 2:39 pm
by John Cartwright
GeXus wrote:Jcart, Yes that does work.. where FALSE does not.. thanks!
Could you explain how the @ works? Thank You.
Like I said already, it supresses the error so you can handle the error however you please. In your case, if the file didn't exist you'd get a warning saying file does not exist, therefore we use the @ to hide this error.
Posted: Sun Nov 19, 2006 6:35 pm
by GeXus
Jcart wrote:GeXus wrote:Jcart, Yes that does work.. where FALSE does not.. thanks!
Could you explain how the @ works? Thank You.
Like I said already, it supresses the error so you can handle the error however you please. In your case, if the file didn't exist you'd get a warning saying file does not exist, therefore we use the @ to hide this error.
Gotcha! Thank you