Sublime Forum

Save as UTF8 without BOM

#1

Hello
A really mandatory feature when developing with PHP is the ability to save a script in UTF8 without the BOM.
Until now, I was using Notepad++ for windows and it has the option: Encoding/ Encode in UTF8 without BOM

As I said this is mandatory for every PHP developer out there, so it would be very usefull to have this in mind.
Thank you for your great product.

0 Likes

#2

Can you explain why this is mandatory?
I use both Notepad++ en Sublime Text for PHP development, and never needed the “UTF8 without BOM” function in Notepad++.

0 Likes

#3

Because of the functions adding headers such : session start, ob start, header, etc link

0 Likes

#4

Yes, this absolutely is a problem, but does Sublime Text 2 save with BOM? When I create a file in Sublime Text 2 it seems to be ANSI encoded when I open it in Notepad++. If I reopen the file in Sublime Text 2 as UTF-8, make changes then save, Notepad++ still shows ANSI encoding.

0 Likes

#5

Sublime Text will save new files as UTF8 by default (without a BOM, of course). If you open a file, the same encoding will be preserved where possible when saving again. The actual encoding used when saving a file is written to the console.

I can’t speak for what Notepad++ may be doing, but UTF8 and ‘ANSI’ encodings are identical if the file only contains ASCII charaters.

0 Likes

#6

[quote=“jps”]Sublime Text will save new files as UTF8 by default (without a BOM, of course). If you open a file, the same encoding will be preserved where possible when saving again. The actual encoding used when saving a file is written to the console.

I can’t speak for what Notepad++ may be doing, but UTF8 and ‘ANSI’ encodings are identical if the file only contains ASCII charaters.[/quote]

That’s good to hear. I don’t know enough about BOM to know why a file might need one, but BOM is trouble for php files.

0 Likes

#7

What does Sublime Text if file contains non-ascii characters? One may still need utf8-without BOM

0 Likes

#8

It tries to preserve the encoding the file was opened with. If all the characters in the buffer are representable in the current encoding, then the current encoding will be used, otherwise the file will be saved as UTF8.

UTF8 is always written without a BOM, unless the file was opened as UTF8-with-BOM. There’s no good reason to ever save a UTF8 file with a BOM, as BOMs are only meaningful for UTF16 and UTF32.

0 Likes

#9

[quote=“jps”]
UTF8 is always written without a BOM, unless the file was opened as UTF8-with-BOM. There’s no good reason to ever save a UTF8 file with a BOM, as BOMs are only meaningful for UTF16 and UTF32.[/quote]

I use it for Python file, Python interpreter detect UTF8 BOM.
Without the BOM, you have to specify the encoding as the first line in the file.

But for Delphi files, I use Windows-1252 encoding.
So I really like an encoding choice before or when saving file.

0 Likes

#10

It’s something I’m planning on adding

0 Likes

#11

[quote=“jps”]

It tries to preserve the encoding the file was opened with. If all the characters in the buffer are representable in the current encoding, then the current encoding will be used, otherwise the file will be saved as UTF8.

UTF8 is always written without a BOM, unless the file was opened as UTF8-with-BOM. There’s no good reason to ever save a UTF8 file with a BOM, as BOMs are only meaningful for UTF16 and UTF32.[/quote]

Thank you very much for clarification :smiley:

0 Likes