file_get_contents php and json_decode error

前端 未结 2 687
庸人自扰
庸人自扰 2021-01-22 08:29

I am facing a weird problem with file_get_contents and decoding to json the result. I have to tell you that this code was fully functional in other server.

2条回答
  •  不思量自难忘°
    2021-01-22 09:14

    The json is simply invalid.

    In front of the first opening curly braces there is the following content (hex encoded) ef bb bf ef bb bf

    It is the utf8 bom.

    There is a question related to deal with exactly that, so I will not cover it here. Read up here:

    How to remove %EF%BB%BF in a PHP string

    and another one dealing specifically with json here:

    Convert UTF-8 with BOM to UTF-8 with no BOM in Python

提交回复
热议问题