I'm trying to parse a JSON encoded string from a cookie and when I run json_decode() on the string it returns as null. It should be a simple operation - what am I missing?
/* Get */
$cookie_exampleData = $_COOKIE['exmaple_data'];
// Retrieves: '{\"FirstName\":\"Angus\",\"LastName\":\"MacGyver\",\"Email\":\"[email protected]\",\"Phone\":\"8185555555\"}'
/* Decode */
$cookie_exampleData_decoded = json_decode($cookie_exampleData);
/* Print */
var_dump($cookie_exampleData_decoded);
// Returns: NULL
In this case, you need remove escaped quotes:
$cookie_exampleData = stripslashes($_COOKIE['exmaple_data']);
See stripslashes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With