php - How to set limit getstr by character?
Get the solution ↓↓↓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
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: cannot use isset() on the result of an expression (you can use "null !== expression" instead)
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.