Home > Article > Backend Development > Solving the problem of illegal character '\ufeff' appearing in the header of PHP response Json string
1 There is a problem. There is a small red dot in front of the response json. When the mouse is placed on it, it will display ufeff
2 Solve the problem
Check the response file encoding, or the file encoding referenced by the response, such as language pack, etc... If you see other encodings, just change it to utf-8 encoding. In my case, utf-8 appeared. -Bom encoding will cause this problem, I changed it to utf-8 and solved it.
Explanation on how php correctly outputs json data
Error example
$result = array('state'=>'123','message' =>'参数错误'); echo 'hello'; echo json_encode($result);
The client receives the first echo statement first but it is not json data .
Another situation is that the statement mysqli_close() is executed and the database is closed, resulting in the inability to receive json data. The specific reason is unknown.
For more PHP related technical articles, please visit the PHP Tutorial column to learn!
The above is the detailed content of Solving the problem of illegal character '\ufeff' appearing in the header of PHP response Json string. For more information, please follow other related articles on the PHP Chinese website!