9

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!

Andres SK
  • 10,779
  • 25
  • 90
  • 152

2 Answers2

25

Try

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

GBD
  • 15,847
  • 2
  • 46
  • 50
13

a small fix to the answer above (can't comment yet)...

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

otherwise you may get stdClass error

Roy B. xSITE
  • 141
  • 1
  • 6