What's  sign at the beginning of my source file?

瘦欲@ 提交于 2019-11-30 03:18:06

问题


I have a PHP source file where  characters automatically got added in! I don't know from where they have come. I'm not getting any parse errors but it results in weird behavior in the execution of the file. E.g. header location functionality is not working sometimes! I'm curious how these kind of symbols are getting auto generated? I'm using UTF-8 encoding & the sign  is not showing in Notepad++ or Windows Notepad but with Netbeans IDE.

Eg. Code:

<?php
echo "no errors!";
header("Location: http://stackoverflow.com");
exit;
?>

What is this? How can I prevent it?


回答1:


You propably save the files as UTF-8 with BOM. You should save them as UTF-8 without BOM.




回答2:


It's called Byte Order Mark, and doesn't always have to be "". http://en.wikipedia.org/wiki/Byte_order_mark

Some Windows applications add BOM by default. In Notepad++ you can use some options in the Encoding menu like Encode in UTF without BOM or Convert to UTF without BOM.




回答3:


I believe that whether you save it UTF-8 with or without BOM it still happens. I don't think it makes a difference.

Try it, see if it helps.




回答4:


From a tool like vi or vim, you can modify and save the file without a BOM with the two following commands :

:setlocal nobomb

and then

:w


来源:https://stackoverflow.com/questions/18845976/whats-%c3%af-sign-at-the-beginning-of-my-source-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!