What's  sign at the beginning of my source

2019-02-13 04:35发布

问题:

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:

If you are using firefox, the characters will show up in your 'paste'. If you switch over to Chrome, then the characters will not appear.