Solved

file_get_contents

Posted on 2011-02-18
3
308 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

807 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