Nirali Joshi Nirali Joshi - 2 years ago 106
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 ?

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download