Reputation: 454
I am using file_get_contents to read json data.
My code is :
//echo $json_url;
$json_data = file_get_contents($json_url);
I am surprise that, the variable $json_data returns null value. When I echo the variable $json_url, it displays the correct url. Tt also displays json record when I manually enter the url in browser.
What can be error here?
Upvotes: 1
Views: 1007
Reputation: 151594
What is the URL?
If you're opening a URI with special characters, such as spaces, you need to encode the URI with urlencode().
Furthermore, are url fopen wrappers enabled?
A URL can be used as a filename with this function if the fopen wrappers have been enabled.
But you will see why the request failed if you enable error reporting.
Upvotes: 1
Reputation: 3414
Try to urlencode the url first
$json_data = file_get_contents(urlencode($json_url));
Upvotes: 0