LoginSignup
13
12

More than 5 years have passed since last update.

json_decodeの返り値がnullになったときの対処

Posted at

jsonを暗号化してCookieに保管し、必要なときに復号化してデータ取り出しをやっていたのですが、json_decodeの返り値がnullになるという問題が発生しました。

データを取り出した際にBOMがついてしまっていたのが原因だったので、

json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $data),true);  

のようにBOMを落としてあげると、無事json_decodeが通りました。

13
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
12