Home>Article>Backend Development> Solving the problem of illegal character "\ufeff" appearing in the header of PHP response Json string

Solving the problem of illegal character "\ufeff" appearing in the header of PHP response Json string

步履不停
步履不停 Original
2019-06-27 18:07:17 4064browse

Solving the problem of illegal character

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 ufeffSolving the problem of illegal character \ufeff appearing in the header of PHP response Json string

2Solve 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 thePHP Tutorialcolumn 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn