PHP Include - Random Characters?!

Soldato
Joined
30 Dec 2003
Posts
5,770
Location
London
Ok, I'm new to all this stuff... but this page has a header/nav menu that's going to remain unchanged on all pages, so I thought about using a php include at the top.

I stripped out the common code, put it in a file called menu.php and added:

<? include('menu.php') ?>

in its place.

http://www.csmager.net/SailIonian3/index.php

is the result. There's a couple of random characters () that appear at the top, and I can't even see them in the resulting source code. Anyone got any ideas?
 
Sort of fixed one problem - got rid of the random characters by changing the encoding to UTF-8 instead of ISO-whatever.

Now there's a gap that appears at the top in IE, but not in firefox. The same code just in an html file doesn't show this behaviour - any ideas on this one?
 
Is your <? include('file.php'); ?> inside another set of <?php tags? That could be your problem. Are you definatly saving with a .php extention? Could you post some of your source code? Just a tip- don't use short tags, always use the full <?php :)
 
Thanks for taking an interest. Here's the index.php file:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sail Ionian Yacht Charters</title>
<link href="normal.css" rel="stylesheet" type="text/css" />
<link href="menu.css" rel="stylesheet" type="text/css" />
</head>

<body>

<? include('menu.php') ?>

<div class="main">

<h1>Sailing charter holidays in Greece</h1>
<h2>Deal with a principle. We are NOT an agent.</h2>
<p><b>Sail Ionian is a small and friendly, family owned, sailing company operating out Vliho Bay (just South of Nidri) on the Greek Island of Levkas. This is a wonderful area to sail "one of the best" with fantastic scenery, set in the safe waters of the Southern Ionian.</b></p>
<p>We provide yachts, for bareboat yacht charters, and for the less experienced whilst you gain confidence, we are pleased to skipper your yacht for part or all of your holiday.</p>
</div>
</body>
</html>

And here's the menu.php

Code:
<div>
<img style="float:right" src="graphics/acc_logos.jpg" alt="Logos" />
<img src="graphics/logo.jpg" alt="Sail Ionian" />
</div>

<div class="menu">

<ul>
<li><span>home
<!--[if IE 7]><!-->
</span>
<!--<![endif]-->

<!--[if lte IE 6]>
</span>
<![endif]-->
</li>


<li><a href="#ref">the yachts
<!--[if IE 7]><!-->
</a>
<!--<![endif]-->


<table><tr><td>

	<ul>
	<li><a href="#ref" title="Mirage 27">Mirage 27</a></li>
	<li><a href="#ref" title="Feeling 286 Special">Feeling 286 Special</a></li>
	<li><a href="#ref" title="Bavaria 30">Bavaria 30</a></li>
	<li><a href="#ref" title="Bavaria 32">Bavaria 32</a></li>
	<li><a href="#ref" title="Bavaria 32">Bavaria 33</a></li>
	<li><a href="#ref" title="Bavaria 36">Bavaria 36</a></li>
	<li><a href="#ref" title="Bavaria 37">Bavaria 37</a></li>
	<li><a href="#ref" title="Bavaria 38">Bavaria 38</a></li>
	<li><a href="#ref" title="Bavaria 39">Bavaria 39</a></li>
	<li><a href="#ref" title="Bavaria 44">Bavaria 44</a></li>
	<li><a href="#ref" title="Bavaria 46">Bavaria 46</a></li>
	</ul>

</td></tr></table>

<!--[if lte IE 6]>
</a>
<![endif]-->
</li>

<li><a href="#REF">our holidays
<!--[if IE 7]><!-->
</a>
<!--<![endif]-->


<table><tr><td>

	<ul>
	<li><a href="#ref" title="what we offer">what we offer</a></li>
	<li><a href="#ref" title="the sailing area">the sailing area</a></li>
	</ul>

</td></tr></table>

<!--[if lte IE 6]>
</a>
<![endif]-->
</li>

<li><a href="#ref">training
<!--[if IE 7]><!-->
</a>
<!--<![endif]-->

<!--[if lte IE 6]>
</a>
<![endif]-->
</li>

<li><a href="#ref">travel
<!--[if IE 7]><!-->
</a>
<!--<![endif]-->


<table><tr><td>

	<ul>
	<li><a href="#ref" title="how to get here">how to get here</a></li>
	<li><a href="#ref" title="flights">flights</a></li>
	<li><a href="#ref" title="taxis">taxis</a></li>
	</ul>

</td></tr></table>

<!--[if lte IE 6]>
</a>
<![endif]-->
</li>

<li><a href="#ref">services
<!--[if IE 7]><!-->
</a>
<!--<![endif]-->


<table><tr><td>

	<ul>
	<li><a href="#ref" title="yacht management">yacht management</a></li>
	<li><a href="#ref" title="yachts for sale">yachts for sale</a></li>
	</ul>

</td></tr></table>

<!--[if lte IE 6]>
</a>
<![endif]-->
</li>

<li><a href="#ref">our clients
<!--[if IE 7]><!-->
</a>
<!--<![endif]-->


<table><tr><td>

	<ul>
	<li><a href="#ref" title="comments">comments</a></li>
	<li><a href="#ref" title="photo galleries">photo galleries</a></li>
	</ul>

</td></tr></table>

<!--[if lte IE 6]>
</a>
<![endif]-->
</li>

<li><a href="#ref">prices
<!--[if IE 7]><!-->
</a>
<!--<![endif]-->

<!--[if lte IE 6]>
</a>
<![endif]-->
</li>
</ul>
</div>

I think it might have something to do with the UTF formatting, but I don't really know. I can't spot any differences to the whole file as an html file and the one that i see when i view source in IE.

For example:
http://www.csmager.net/SailIonian3/index2.html shows the same issue, whereas:
http://www.csmager.net/SailIonian3/index3.html works fine. Spot the difference in the code? I can't!
 
Try this as your character encoding:

Code:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

Also, I would change your PHP short tags ( <? ) to the full tags ( <?php ) as it can cause problems if you move hosts etc :)
 
Trigger said:
Try this as your character encoding:

Code:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

Also, I would change your PHP short tags ( <? ) to the full tags ( <?php ) as it can cause problems if you move hosts etc :)
I did orignally have that as the encoding, and that caused random characters at the top. I'll try again in a minute and see what happens.
 
That's funny. I've just looked at those links again and they're displaying the menus fine and the pages look exactly the same :confused:

EDIT: Change your short tags to full tags- I'm not sure whether your host supports them.
 
Code:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
change to
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
Dj_Jestar said:
Code:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
change to
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

He's already tried that and said it removes the funny characters but the include doesn't work apparantly although on the two links posted the menu is there :confused:

Try using

Code:
<?php
         
         include 'menu.php';

?>

:)
 
Trigger said:
He's already tried that and said it removes the funny characters but the include doesn't work apparantly although on the two links posted the menu is there :confused:
The include definitely works, it's just adding about a 1cm white gap to the top of the page for some entirely unknown reason - only happens in IE.

EDIT: Woo! Seem to've fixed it. Left it as ISO encoded and made sure that the files were saved as ANSI rather than UTF-8. Gap vanished.

Still no idea why it adds it though...
 
csmager said:
The include definitely works, it's just adding about a 1cm white gap to the top of the page for some entirely unknown reason - only happens in IE.

EDIT: Woo! Seem to've fixed it. Left it as ISO encoded and made sure that the files were saved as ANSI rather than UTF-8. Gap vanished.

Still no idea why it adds it though...

Oh good, glad you got it sorted mate :)
 
Back
Top Bottom