2 replies [Last post]
Mile
Mile's picture
Offline
Enthusiast
Glasgow, UK
Last seen: 14 years 4 weeks ago
Glasgow, UK
Joined: 2005-01-22
Posts: 81
Points: 0

Something I've noticed and I was wondering if it happens to others or anyone knows about it.

Everytime I do a PHP page I seem to get a few spaces appearing before the DOCTYPE declaration.

Known phenomenon or am I making a silly little mistake.

Even something as simple as:

<?php
include("info.inc");
page_header();
page_footer();
?>

where info.inc is:

function page_header() {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Talk History - Resource</title><link href="styles/style1.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
}

function page_footer() {
?>
</body>
</html>
<?php
}

The code generated here is a current example.

Tags:
Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 9 years 41 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

PHP: Spaces atop page

I was taught to always make the "<?php" the first line in the file and to ensure there were never any blank lines before you started outputing your HTML. I have never tested what happens if there are blank lines ...

(1) are there any blank lines outside the <?php ... ?> and before the <!DOCTYPE in info.inc?
(2) are there any blank lines in your main page before the <?php ?

Mile
Mile's picture
Offline
Enthusiast
Glasgow, UK
Last seen: 14 years 4 weeks ago
Glasgow, UK
Joined: 2005-01-22
Posts: 81
Points: 0

PHP: Spaces atop page

info.inc had a few lines at the very bottom. I thankyou. That has solved it. Laughing out loud