JSON file store in PHP variable -
when open https://graph.facebook.com/me?access_token=xxxx json file. want store in php variable , use json_decode() function convert string. how can directly store json content in php variable giving link.
simplest solution use http stream wraper file_get_contents().
$data = json_decode( file_get_contents('theurl') );
if need more control on http request made, take @ stream context options.
if need more error handling take @ stream notifications.
can use
$fp = fopen('http://....', 'rb'); if ( !$fp ) { someerrorhandling(); } $data = json_decode( stream_get_contents($fp) );
in case can combine stream_get_meta_data() more http relaed stuff request/stream.
see also: allow_url_fopen (because url wrappers can disabled via configuration...)
Comments
Post a Comment