Home > Backend Development > PHP Tutorial > 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

步履不停
Release: 2023-04-06 22:40:02
Original
4365 people have browsed it

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

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);
Copy after login

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!

Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template