Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP include causes white space at the top of the page

Tags:

php

I have a problem on a site that I am making. There is this line of white space at the top of my page. I can not find out where it is coming from. It might be because of extra line breaks in my page thanks to php include() or maybe it is just some faulty css.

like image 356
Daniel says Reinstate Monica Avatar asked Apr 17 '12 21:04

Daniel says Reinstate Monica


People also ask

How do I get rid of the white space at the top of HTML?

Solution: You can use one of the following: Answer1: The * selector means, select all elements and set their margin and padding to 0.

What does PHP do with whitespace?

The ctype_space() function in PHP check for whitespace character(s). It returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters.

Does PHP care about whitespace?

Whitespaces are generally ignored in PHP syntax, but there are several places where you cannot put them without affecting the sense (and the result).

Is PHP white space sensitive?

PHP is whitespace insensitive PHP whitespace insensitive means that it almost never matters how many whitespace characters you have in a row. one whitespace character is the same as many such characters.


2 Answers

I got it! I must admit, this was a very strange one.

This was my exact problem, and his solution fixed it perfectly.


The problem was because of the include().

When you save a page as UTF-8, a special signature called a byte-order mark (or BOM) is included at the beginning of the file, indicating that it is a UTF-8 file. You can only see BOMs with low level text editors (such as DOS edit). You need to remove this signature from the included file in order to get rid of the white space at the top of the page.

DOS edit

like image 52
Daniel says Reinstate Monica Avatar answered Sep 22 '22 10:09

Daniel says Reinstate Monica


In Notepad++ you can change the encoding of the file to "UTF-8 without BOM" from the "Encoding" menu. This fixes the problem for me.

like image 34
Bruno Avatar answered Sep 23 '22 10:09

Bruno