由于哪些字符不工作json_decode() ?——PHP



我有一个javascript文件,里面有一个数组,我想在php文件中包含javascript,提取数组并将其转换为php。奇怪的是,json_decode()不工作,可能是由于一些字符。

你能告诉我哪些字符是不允许的,为什么?

$file_contents = 'var dati_login = [["1111","2021-10-30"],["_fbp=fb1111152; i18next=en-US; cookielaw_accepted=1; _ga=GA1.1.1111.1611118; e2sid=11115; _lr_uf_-qrlpn5=111-e111e-424c-9043-1111; _lr_tabs_-qrlpn5/e2={"sessionID":0,"recordingID":"111159d18955a","lastActivity":163480041112}; _lr_hb_-qrlpn5/e2={"heartbeat":1118402}; _ga_THFZJ5FYF8=GS1.1.11110.7.1.1111468.0","2021-10-30"]]';
$json_string = substr($file_contents,strpos($file_contents,'['));
$array_dati = json_decode($json_string);    //ecco l'array in php
print_r($array_dati);

json_decode()不工作…我知道问题是在array[1][0],但我不明白哪些字符....

您需要将$file_contents的内部数据编码为">

$file_contents = 'var dati_login = [["1111","2021-10-30"],["_fbp=fb1111152; i18next=en-US; cookielaw_accepted=1; _ga=GA1.1.1111.1611118; e2sid=11115; _lr_uf_-qrlpn5=111-e111e-424c-9043-1111; _lr_tabs_-qrlpn5/e2={"sessionID":0,"recordingID":"111159d18955a","lastActivity":163480041112}; _lr_hb_-qrlpn5/e2={"heartbeat":1118402}; _ga_THFZJ5FYF8=GS1.1.11110.7.1.1111468.0","2021-10-30"]]';

最新更新