Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

php - 如何避免在PHP中回显字符65279?(How to avoid echoing character 65279 in php?)

I have encountered a similar problem described here (and in other places) - where as on an ajax callback I get a xmlhttp.responseText that seems ok (when I alert it - it shows the right text) - but when using an 'if' statement to compare it to the string - it returns false.(我在这里 (和其他地方)遇到了类似的问题-在ajax回调中,我得到一个看起来不错的xmlhttp.responseText(当我发出警报时-它显示正确的文本)-但是当使用'if'时将其与字符串进行比较的语句-返回false。)

(I am also the one who wrote the server-side code returning that string) - after much studying the string - I've discovered that the string had an "invisible character" as its first character.((我也是编写返回该字符串的服务器端代码的人)-在研究了字符串之后-我发现该字符串的第一个字符为“不可见字符”。) A character that was not shown.(未显示的字符。) If I copied it to Notepad - then deleted the first character - it won't delete until pressing Delete again.(如果我将其复制到记事本中-然后删除了第一个字符-直到再次按Delete键,它才会删除。) I did a charCodeAt(0) for the returned string in xmlhttp.responseText.(我为xmlhttp.responseText中的返回字符串做了一个charCodeAt(0)。) And it returned 65279 .(然后返回65279 。) Googling it reveals that it is some sort of a UTF-8 control character that is supposed to set "big-endian" or "small-endian" encoding.(谷歌搜索它表明它是某种UTF-8控制字符,应该设置“大端”或“小端”编码。) So, now I know the cause of the problem - but... why does that character is being echoed?(所以,现在我知道了问题的原因-但是...为什么要回显该字符?) In the source php I simply use(在源PHP中,我只是使用) echo 'the string'... and it apparently somehow outputs [chr(65279)]the string...(它显然以某种方式输出[chr(65279)]字符串...) Why?(为什么?) And how can I avoid it?(我该如何避免呢?)   ask by Yuval A. translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...