Kyle Kyle - 2 months ago 5
JSON Question

How to return and format an array in php by using curl

I know this maybe an easy question but I am still stucked here.

I am calling an API, this is my code:

$access_token = 'asdfasdfasdfasdf';
$uid = '12345678';
$url = 'https://api.asd.com/2/statuses/user_timeline/ids.json?uid='.$uid.'&access_token='.$access_token.'&count=5';
$ch = curl_init();
curl_setopt($ch,CURLOPT_HEADER,false);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$content=curl_exec($ch);
curl_close($ch);
echo $content;


This is what I got:

{"statuses":"4023805771256802","4023694609717194","4021770053107357","4021769599890997","4021769217975680"],
"marks":[],
"hasvisible":false,
"previous_cursor":0,
"next_cursor":0,
"total_number":94,
"interval":0,
"uve_blank":0}


What I want is having an array of 'statuses' only, because I want to use the data in 'statuses' only.

Anyone can give me a hint? I will be really appreciated.

Answer

That is JSON data...use json_decode() to convert to array

$arr = json_decode($content, TRUE);

$statuses = $arr['statuses'];
Comments