Home > Article > Backend Development > Why Does Character 65279 Appear in My PHP Response?
Understanding the Mystery of Character 65279 Echo in PHP
Despite encountering a puzzling issue during an AJAX callback, where text displayed correctly in an alert but failed to match in an 'if' statement, the culprit was a hidden character at the beginning of the response text. Intriguingly, this character had a character code of 65279.
Further investigation revealed that this character, originating from the server-side PHP code, was an invisible UTF-8 control character intended to define the encoding of the response. However, the question arises: why was this character being echoed inadvertently?
Upon closer examination of the PHP code, a simple 'echo' statement was used to output the response. However, it became apparent that Notepad, which was used to save the PHP file, subtly added a Byte Order Mark (BOM) to the file. This BOM consisted of three bytes: EF BB BF, and its purpose was to indicate that the encoding of the file was UTF-8 with big-endian byte order.
While PHP generally handles BOMs without issue, problems can arise when one PHP file is included into another. In such cases, the BOM can cause strings to be displayed with character 65279 prepended to them, leading to unexpected behavior in comparisons.
Thankfully, there are ways to avoid this issue:
By implementing these solutions, developers can prevent the unwelcome appearance of character 65279 in their PHP responses, ensuring that comparisons and other string operations function as intended.
The above is the detailed content of Why Does Character 65279 Appear in My PHP Response?. For more information, please follow other related articles on the PHP Chinese website!