user3051901
user3051901

Reputation: 25

not able to convert json data in php array in wordpress?

i have in the following data format, i think it is j son i want to echo image in it but json decode is not working on it please help me integrating my coding into WordPress platform

a:5:{s:4:"name";s:36:"e4da3b7fbbce2345d7772b0674a318d5.jpg";s:4:"type";s:10:"image/jpeg";s:5:"error";i:0;s:4:"size";i:2795;s:10:"thumb_name";s:42:"e4da3b7fbbce2345d7772b0674a318d5_thumb.jpg";}

Upvotes: 1

Views: 534

Answers (1)

Cyclonecode
Cyclonecode

Reputation: 30071

You will need to use unserialize() to convert the data to its original form:

$data = 'a:5:{s:4:"name";s:36:"e4da3b7fbbce2345d7772b0674a318d5.jpg";s:4:"type";s:10:"image/jpeg";s:5:"error";i:0;s:4:"size";i:2795;s:10:"thumb_name";s:42:"e4da3b7fbbce2345d7772b0674a318d5_thumb.jpg";}';
$decoded = unserialize($data);
// then you should be able to get the path to the image
print $decoded['name'];

Upvotes: 2

Related Questions