views:

65

answers:

3

When I include some PHP in my page to populate a load of HTML everything is preceeded with the characters . It's probably something daft but it's driving me nuts. I'm a newcomer to PHP so kid gloves please.

This is my include statement <?php $PSName="Solar Numbers"; $whereto="bot"; include("../php/menu.inc.php");?>

and this is the code that's doing the damage

   print <<<END
<a href="$pgurl">
<div id="layer1" style="background: url('$picurl'); 
position: absolute; width: 150px; height: 41px; z-index: 1; color: #FFFFFF; font: caption;
left: 14px; top: $topstr;
font-family: Arial, Helvetica, sans-serif; font-weight: bolder; text-decoration: none;
text-transform: capitalize; text-align: center; vertical-align: middle; font-size: xx-small;">
<br>
<font size="+0">$pgnm</font>
</div>
</a>
END;

it's output several times in a loop in the program and it's only the first time round I get the spurious characters.

Help please

SteveK

A: 

The characters look like UTF-8 BOM characters.

BojanG
+1  A: 

Save the file as UTF-8 without the signature (BOM).

Those characters are the Unicode code point U+FEFF which is needed for UCS-2, UCS-4, UTF-16 and UTF-32 to indicate the byte order (little- or big-endian) – the code point itself is a zero-width no-break space. That means any application not stripping it won't run into problems as long as it supports Unicode output. However, if your PHP file begins with it (in UTF-8), PHP is not smart enough to do anything with it and since it's page content as far as PHP is concerned, it will get printed. This also means that you can't do a redirect or set cookies or start a session if this happens as PHP already sent part of the page output.

Joey
As I said I'm a real newbie, how do I save it as UTF? What do I save the include or the parent? Thanks everybody, patience is what I need, as an ex assembler programmer this is new ground for me.
Steve K
@Steve: That depends on the editor you're using to write your files. I'm not psychic and can't guess what you're using. In Expression Web you can right-click > Encoding and de-select "Include a Byte Order Mark". In Far it is done with Shift+F2. Can't say anything about other editors, though.
Joey
A: 

If you use Dreamweaver, the preselected option for "source file creation" is:

use utf8 BOM [x]

deselect it and create a file (menu.inc.php) without the BOM (byte order mark).

Regards

rbo

rubber boots
Have fixed problem now by including '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' in the calling pages. Thanks all.
Steve K