I finally figured out that this problem was being caused by a known problem with UTF-8 encoded pages sometimes creating an extra line of code at the top of pages/included files (link to w3.org's explanation of this issue), and since these aren't visible removing any visible spaces doesn't correcting it. I hadn't even known that this was being set anywhere since all the web development environments I've used (Visual Web Developer and several others) automatically save documents in UTF-8.
The best solution that I've found is to save the files in a text editor as UTF-8 without BOM. The way to do this in Notepad++ or Visual Studio/Visual Web Developer (the two text editors that I use) are:
- Notepad++ - Click on the 'Convert to UTF-8 without BOM' option under the Encoding Tab, and then resave the documents.
- Visual Studio/Visual Web Developer Express 2010 - Use the Advanced Save Options to save with the correct UTF-8 encoding - Unicode (UTF-8 without signature) - Codepage 65001. In order to access the Advanced Save Options in Visual Web Developer Express, select 'Save As', and then click on the little down arrow on the 'Save' button to 'Save with Encoding'.
I also had to change the charset within the HTML document to avoid getting strange characters when I echo'd from php to an html document.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
It seems to work with utf-8 set in the html and No BOM in the PHP, but if you'd like to use No BOM in the HTML as well, I found 3 syntax options that worked in Firefox: charset=utf-8 without BOM; charset=UTF-8 no-BOM; charset=UTF-8 encoding without BOM (I'll update this once I've had a chance to test the code a bit more).