![]() |
File_Get_Contents exception
Is it possible to somehow catch the response of file_get_contents like for example:
if everything is okay with the URL go ahead and continue, if an error occured we should try something else? Thanks! |
To put it simply, no.
file_get_contents is a highly primitive function. cURL is the way to go if you want more advanced feedback. I have written you a function that will do just this, if the HTTP code is not 200 (OK) then it will return false, else it will return the contents of the website.PHP Code:
|
wild, where have you learned all? :P You seem to know the solution to every problem, just wondering where you've learned :)
|
Good question, sir! Reading has taught me a lot, naturally. Though the best education tool is just having a stab at it yourself and then having people to ask if you really can't figure it out - that's where TalkPHP comes in :) !
|
Uhm, so do you have an idea on what I can code? Cause I'm out of ideas..
And nothing too hard, I'm sure you know how much knowledge I have, by now :) |
I remember I started off with a simple code paster. You are presented with a textfield for the code, a dropdown for the language. Submit the code and you're then given a link to show to any one who's interested in helping you. Can have that with line numbers. Very much like NoPaste.
Other than that I'm not really any good at dreaming up scenarios :( |
Damn, haha, that sounds hard... okay, I'll try.. >.< :P
|
Quote:
file_get_contents() will 'catch' the response from whatever URL you pass to it, that is the function's purpose. If you're wanting to look at the headers returned from the remote server, then after calling file_get_contents() you can access the global variable, $http_response_header which holds all of the headers from the last response.To check for "200" like Wildhoney's CURL example you can do: PHP Code:
|
| All times are GMT. The time now is 11:59 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0