utf8 without BOM encoding in eclipse

byte-order-mark, eclipse, php

Solution

In eclipse, just change the encoding of the file to iso (Right click on file - > Properties) and delete the first three BOM characters, save file and reopen it.

Problem

After some headache I figured out that eclipse using set encoding UTF8 (with BOM) causes an error. It causes whitespace to be added when you use an include causing the headers of a webpage to render within the body in chrome. ie. on index.php with no gap before or after the of course ``` <?php include_once('header.php'); ?><body>test</body> ``` and header.php having (without gaps again of course) ``` <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>test title</title> </head> ``` Then the test title appears within the body (not in view source, but in the console in chrome). This causes a gap at the top of the page. Opening the index.php and header.php in notepad++ and changing the encoding to UTF8 without BOM solves the problem. How can I fix this in Eclipse?! Switching to notepad++ is not desireable, too many good features in eclipse that are useful (better autocomplete, automatic versioning etc). A mystery to me...

Original source

Related problems