PHP file_get_contents returning false

Try this:

$query = http_build_query(array('search'=>$as_any, 'location'=>$location));
$url = "http://jobs.github.com/positions.json?" . $query;

The problem is that you weren't URL-encoding the search term, which contains a space. The request was returning a 400 error from the server, which you'd have noticed if you had error reporting enabled.


Probably allow_url_fopen in your php.ini: http://php.net/manual/en/filesystem.configuration.php

Needs to be allowed.


You may need to enable allow_url_fopen in your php.ini

http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

From the documentation:

This option enables the URL-aware fopen wrappers that enable accessing URL object like files.

Your server may be preventing you from opening a file located at a URL using file_get_contents.


In my case replace file_get_contents() on this simple function

function get_content($URL){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $URL);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

Tags:

Php

Json