Remove BOM from file - how ?

I downloaded file index.php from server. This file is incorect saved with BOM (not by me but by other person).
Now PHP generate something like this:

Warning:  session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /index.php:1) in /inc/config.php on line 2
Warning:  session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /index.php:1) in /inc/config.php on line 2
Warning:  Cannot modify header information - headers already sent by (output started at /index.php:1) in /inc/config.php on line 12

Question.
How can I remove BOM from this file via PHPStorm ?

5 comments
Comment actions Permalink

Hi Daniel,

There is no special action in PhpStorm to Add/Remove BOM signature. But there is one way how this can be achieved it without leaving PhpStorm and not using any 3rd party program (like Notepad++, for example). This is not very practical (in my opinion), but works :).

The trick is:
1) create new empty file (for example: temp123.php)
2) make sure that code-page/encoding for that file is UTF-8
3) copy whole content from original to newly created file (select all, copy, go to another tab, paste) and save
4) delete original file and rename new file -- give it the name of the original file.

0
Comment actions Permalink

Exactly what I was looking for.  Thanks Andriy :)

0
Comment actions Permalink

Are you sure? :)

"File | Remove BOM" action is available for like 2 years now...

3
Comment actions Permalink

:^O That would have saved me a couple of hours had i known about it yesterday.

I see that you can ctrl+a all the files in the Projects pane and then alt+f -> 'Remove BOM' too to batch remove all boms from all files.

Very cool!

Thanks for the update. :)

0
Comment actions Permalink

@Andriy Bazanov Thanks man! :-D

0

Please sign in to leave a comment.