Solved

file_get_contents

Posted on 2011-02-18
3
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 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