I need help getting specific data from an api. The json data looks something like this
array(1)
{
[0]=> string(18) "{"errorCode":0
"members":[
{"userId":"32"
"name":"Joy"
"age":"22"
"country":"USA"
"orders":133
"active":0}
{"userId":"38"
"name":"greg"
"age":"29"
"country":"CA"
"orders":19
"active":0}
{"userId":"29"
"name":"bob"
"age":"33"
"country":"USA"
"orders":67
"active":0}
],"total":59},
Array"
}
What I want to get back is only people in the US that are over 25.
My code so far is
<?PHP
$url="https://api.someplace.com";
$ch = curl_init();
curl_setopt( $ch, CURLOPT_USERAGENT, $url );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
$content = curl_exec( $ch );
$response = curl_getinfo( $ch );
$combine = "$content, $response";
curl_close ( $ch );
$openBracket = str_replace("{","{\n",$combine);
$comma = str_replace(",",",\n",$openBracket);
$result = str_replace( ',', '<br />', $comma );
$ary = array($result);
echo $ary;
?>
This returns the whole json file but when I try to do anything with the data it doesn't work. I know I need some kind of foreach loop, if/else statements and maybe a json_decode, I wont bore you with what I all tried so far because none of it worked, I only get returns of all the json data back, NULL, {, or just a blank page.
I'm not sure if cURL is messing things up, I never used it before, I have to with this one because it's a https link. Please let me know the best way to get this data.