I have a little problem that I can't get my head around. I am new to php. I want to extract the top_secret from here:
Array ( [headers] => Requests_Utility_CaseInsensitiveDictionary Object ( [data:protected]
=> Array ( [content-type] => application/json; charset=UTF-8 [expires] => Sat, 01 Jan 2000 00:00:00
GMT [content-length] => 250 ) ) [body] =>
{"top_secret":"WELLTHISISTOPSECRETSONOONESHOULDEVERSEEIT","token_type":x,"expires_in":x} [response] =>
Array ( [code] => 200 [message] => OK ) [cookies] => Array ( ) [filename] =>
[http_response] => WP_HTTP_Requests_Response Object ( [response:protected] =>
Requests_Response Object ( [body] =>
{"top_secret":"WELLTHISISTOPSECRETSONOONESHOULDEVERSEEIT","token_type":x,"expires_in":x} [raw] =>
HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8
{"top_secret":"WELLTHISISTOPSECRETSONOONESHOULDEVERSEEIT","token_type":"bearer","expires_in":x}
What I tried:
<?php
parse_str($response['body'], $response);
$field=$response['top_secret'];
echo $top_secret;
?>
But nothing appears. Any idea what I am doing wrong? I want to echo the following string:
WELLTHISISTOPSECRETSONOONESHOULDEVERSEEIT