tags:

views:

65

answers:

2

i have the strangest bug. in my php file i include several php files:

<?php
include("a.php");
include("b.php");
include("c.php");
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="src/main.css" ></link>
<script src="src/jquery-1.3.2.js" type="text/javascript" ></script>
</head>
<body>
some more code here...

when the page is rendered, i see that there are about 18px added to the layout, and the link and script tags were moved inside the body section. If i remove the include of b.php and c.php it doesn't happen.

any thoughts?

A: 

Check there's no whitespace at the end of the included files after you final closing ?>. The easiest way to be sure there's nothing after that is to remove it altogether:

<?php
// here is my file
// and i don't have to close the PHP tag
// woo
nickf
And remember: the closing tag can only be removed if there is no HTML after it!
Julio Greff
+2  A: 
  1. check for BOM.
  2. Check for white spaces in your files
  3. make sure to remove the ending ?> from your PHP files, if this is the last characters in the file.

4. do

 ?><html>

instead of

?>
<html>
Itay Moav
whitespace before the <html> should be ignored. also, what is BOM?
nickf
BOM == bit order mark. For unicode, where characters takes more then one byte, say ef67, this can also be represented as 67ef. The BOM is three characters added at the start of the unicode file which tells the program what is the correct order. Google it, Wiki has a better explanation.
Itay Moav
i changed in notepad++ the format from utf-8 to utf-8 without BOM and it solved the problemThanks a lot!Amir.
Amir