Reputation: 504
What would the syntax be to pull an external data source, which has the data in JSON format into a variable to be worked with. I understand using json_decode($variable) but how would i load the actual data into that variable for decoding?
Upvotes: 5
Views: 6983
Reputation: 1962
Use anything from fopen + fread to php curl library. With fopen you could open a remote file if php settings allows you to. I think you should be able to do it now. If you still can't do it, let us know.
Upvotes: 0
Reputation: 5438
If by external you mean that it's hosted on a 3rd-party domain name, then you open a socket and GET the data:
$variable = file_get_contents('http://example.com/data.json');
$decoded = json_decode($variable);
Upvotes: 7
Reputation: 799240
With fopen()
, fread()
, and fclose()
, or with file_get_contents()
.
Upvotes: 1
Reputation: 18761
Using file_get_contents()
?
(You must have allow_url_fopen true)
Upvotes: 0