The following code is to query an online thesaurus for a search engine I'm building as a college project, but I'm having problems with file_get_contents
"failed to open stream" errors. When I send a word the thesaurus doesn't recognize, it throws up an error. I'm trying to write a piece of code that will ignore the error and just proceed without the information.
$thesaurus_search="http://words.bighugelabs.com/api/2/0089388bb57f/".$this->formatted_query."/php";
$result_thesaurus=file_get_contents($thesaurus_search);
I tried:
if (file_get_contents($thesaurus_search) != NULL)
{ // do stuff }
...but its not working because it still returns some sort of string.
What can I do to handle such cases?
How to fix this error? You have to show us the code and tell us what you are trying to do so that someone can help you. Replace file_get_contents with CURL method to resolve Error of file_get_contents (): http:// wrapper is disabled in the server configuration by allow_url_fopen=0
file_get_contents () is not allowed to open files with a scheme of https://. The reason for this is your PHP runtime config of allow_url_fopen set to 0. From the Runtime configuration manual: " This option enables the URL-aware fopen wrappers that enable accessing URL object like files.
@primehalo go to WHM > MultiPHP INI Editor > select PHP version and set allow_url_fopen to Enabled. In my cPanel there is a checkbox to enable allow_url_fopen in (Software)Select PHP Version > Options (tab at the top), although if this doesn't solve it for you see my answer below. Use cUrl instead of file_get_contents.
If you are are trying to use file_get_contents () function to fetch the contents of a URL and you receive Error something like Enable the allow_url_fopen parameter in your php.ini configuration. Although this is an easy approach this is not recommended because of the security holes it opens.
If you don't want file_get_contents
to report HTTP errors as PHP Warnings, then this is the clean way to do it, using a stream context (there is something specifically for that):
$context = stream_context_create(array(
'http' => array('ignore_errors' => true),
));
$result = file_get_contents('http://your/url', false, $context);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With