As I've been taught here, don't ever cut it off or mess with strings. decode the JSON and extract the relevant property
If you response is like that:
\"request_time":"2021-07-11 04:52:07\",\"elapsed_return_time_milliseconds\":26.65,\"access_ip\":null,\"error\":null,\"amount_sent\":1}
Means that you need decode with
$json = json_decode($string, true);
This is my updated code to get values, where $inicio contains the JSON response:
$inicio = curl_exec($ch);
$json = json_decode($inicio, true);
$gettime = $json['header']['request_time'];
echo json_encode(array("status" => 1, "msg" => "Error $number - Empty Response"));
}else{
echo json_encode(array("status" => 0, "msg" => "Ok $Number - $reqtime Response"));
}
The output now is:
Ok 123456 - $2021-07-11 04:52:07 Response
So if I need get request_time value from this response:
"header": {
"api_version": "3.0.0",
"type_connection": 1,
"user": "",
"request_time": "2021-07-11 05:46:24",
"elapsed_return_time_milliseconds": 28.34,
"access_ip": null,
"error": null,
"amount_sent": 1
},
I can use this:
$gettime = $json['header']['request_time'];
Thank you very much! Please formulate the answer so I can mark as correctly