Nirali Joshi Nirali Joshi - 5 months ago 12x
PHP Question

extract parameter from response

I am getting this string from CURL response

{status: 'false',description:'5400'}

I want to extract description parameter only.
I want $description = 5400 ;

How to do this ?


You have a bad json response, you have to change your json code and than using the following code you can access the variable.

$response = '{"status":false,"description":5400}';
$response_array = json_decode($response);
echo $response_array->description;

And if you want to get the value of description with the existing bad json, you can do following thing.

$response = "{status:'false',description:'5400'}";
$r = explode("description:'", $response);
$description = rtrim($r[1],"'}");
echo $description;