简体   繁体   中英

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

I know this maybe an easy question but I am still stuck 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.

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

$arr = json_decode($content, TRUE);

$statuses = $arr['statuses'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM