Solved

file_get_contents

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 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

16 Experts available now in Live!

Get 1:1 Help Now