0

这是我直接回显 cookie 时显示的输出,然后尝试 json_decode 它。

$_COOKIE['mycookie'] = {\"table_name\":\"wp_customtable\",\"time\":\"2013-09-26 08:18:23\",\"post_id\":null,\"referer\":\"www.bing.com\",\"keywords\":\"350 rear main seal replacement 11\",\"full_referrer\":\"http:\\/\\/www.bing.com\\/search?q=350+rear+main+seal+replacement+11&go=&qs=n&form=QBRE&pq=350+rear+main+seal+replacement+11&sc=0-32&sp=-1&sk=&cvid=dc09d67a2d214c8394bd39f2b28cf6cc\",\"ip\":\"123.45.67.89\"}

$cookie = $_COOKIE['mycookie'];
$output = json_decode($cookie, true);

var_dump($cookie);

string(392) "{\"table_name\":\"wp_customtable\",\"time\":\"2013-09-26 08:18:23\",\"post_id\":null,\"referer\":\"www.bing.com\",\"keywords\":\"350 rear main seal replacement 11\",\"full_referrer\":\"http:\\/\\/www.bing.com\\/search?q=350+rear+main+seal+replacement+11&go=&qs=n&form=QBRE&pq=350+rear+main+seal+replacement+11&sc=0-32&sp=-1&sk=&cvid=dc09d67a2d214c8394bd39f2b28cf6cc\",\"ip\":\"123.45.67.89\"}

var_dump($output);
NULL
4

1 回答 1

2

只需去掉引号前的斜杠即可:

json_decode(str_replace('\"', '"', $cookie), true);

见小提琴

于 2013-09-26T16:21:53.480 回答