Solved

file_get_contents

Posted on 2011-02-18
3
294 Views
Last Modified: 2012-08-14
In PHP using function file_get_contents(), is it possible to hide when it outputs warning or error (for instance when http request is denied it would display warning, is there any way to get rid of that?

Maybe with try, catch?
0
Comment
Question by:GVNPublic123
3 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 34927412
You can just use @file_get_contents(), which will supress the warnings
0
 

Author Comment

by:GVNPublic123
ID: 34927441
Well, as this is only 1 time occurrence requirement, @ will probably do the job. Thanks!
0
 
LVL 3

Expert Comment

by:thecrew
ID: 34927445
Assuming something like this:
$site="http://www.google.com";
$content = file_get_content($site);
echo $content;

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_content: $content = @file_get_content($site); (note, use this sparingly!! See Error Control Operators)

or

$content = @file_get_contents("http://www.google.com");
if (strpos($http_response_header[0], "200")) {
   echo "SUCCESS";
} else {
   echo "FAILED";
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now