3
<!DOCTYPE html>

This is the code.

How can I fix that?

I tested the HTML/CSS/JavaScript before integrating the code with Laravel.

Remi Guan
  • 21,506
  • 17
  • 64
  • 87

2 Answers2

5

Make sure your PHP files don't have the closing tags (?>). They might add whitespace to your HTML.

For more info, see the PHP docs:

If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.


You might also want to take a look at this post: Why would one omit the close tag?

Community
  • 1
  • 1
Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
  • Wait, so you're saying *not* to add closing tags to the PHP files? – Blender Jul 30 '12 at 20:09
  • @Blender - That's correct. If you have any whitespace after your closing tags, they'll be sent to the browser as part of the HTML output. To avoid this, you should never close your PHP tags in a PHP only document. – Joseph Silber Jul 30 '12 at 20:10
  • It should be noted that even if you try to delete any empty characters after a closing tag - it's probably your text editor that's configured to always add a new line. – Narf Jul 30 '12 at 20:21
0

I know this is few years late but for other people.

change the page encoding to UTF-8 without BOM and it will be solved.