Converting a stringified json structure to PHP array

Andres SK picture Andres SK · Dec 11, 2012 · Viewed 13.9k times · Source

I'm saving a cookie with json data. Example of echo $_COOKIE['data']

[{\"date\":1355249777,\"title\":\"junior\"},{\"date\":1355249747,\"title\":\"christopher\"},{\"date\":1355249139,\"title\":\"melfi\"},{\"date\":1355249123,\"title\":\"tony\"},{\"date\":1355248876,\"title\":\"carmela\"},{\"date\":1355248859,\"title\":\"meadow\"}]

The data was pure javascript, then passed by JSON.stringify and then stored in the cookie. Now i need to convert it to a php array. I tried a json_decode approach but it returns null. Any ideas? Thanks!

Answer

GBD picture GBD · Dec 11, 2012

Try

json_decode(stripslashes($_COOKIE['data']));