Question

When using the php include function the include is succesfully executed, but it is also outputting a char before the output of the include is outputted, the char is of hex value 3F and I have no idea where it is coming from, although it seems to happen with every include.

At first I thbought it was file encoding, but this doesn't seem to be a problem. I have created a test case to demonstrate it: (link no longer working) http://driveefficiently.com/testinclude.php this file consists of only:

<? include("include.inc"); ?>

and include.inc consists of only:

<? echo ("hello, world"); ?> 

and yet, the output is: "?hello, world" where the ? is a char with a random value. It is this value that I do not know the origins of and it is sometimes screwing up my sites a bit.

Any ideas of where this could be coming from? At first I thought it might be something to do with file encoding, but I don't think its a problem.

Was it helpful?

Solution

What you are seeing is a UTF-8 Byte Order Mark:

The UTF-8 representation of the BOM is the byte sequence EF BB BF, which appears as the ISO-8859-1 characters  in most text editors and web browsers not prepared to handle UTF-8.

Byte Order Mark on Wikipedia

PHP does not understand that these characters should be "hidden" and sends these to the browser as if they were normal characters. To get rid of them you will need to open the file using a "proper" text editor that will allow you to save the file as UTF-8 without the leading BOM.

You can read more about this problem here

OTHER TIPS

Your web server (or your text editor) apparently includes a BOM into the document. I don't see the rogue character in my browser except when I set the site's encoding explicitly to Latin-1. Then, I see two (!) UTF-8 BOMs.

/EDIT: From the fact that there are two BOMs I conclude that the BOM is actually included by your editor at the beginning of the file. What editor do you use? If you use Visual Studio, you've got to say “Save As …” in the File menu and then choose the button “Save with encoding …”. There, choose “UTF-8 without BOM” or something similar.

It doesn't show up on the rendered page in Firefox or IE but you can see the funny character when you View Source in IE

enter image description here

Is this on a Linux machine? Could you do find & replace with vim or sed to see if you can get rid of the 3F that way?

If it's on Windows, try opening include.inc with Notepad to see if the funny char is visible & can be deleted.

I'd also be curious to see what happens if you copy the code out of the include and just run it by itself.

Character 3F actually is the question mark, it isn't just displaying as one.

I get the same results as Thomas, no question mark showing up.

In theory it could be some problem with a web proxy but I am inclined to suspect a stray question mark in your PHP markup...which perhaps you have fixed by now so we don't see the problem.

I see hello, world on the page you linked to. No problems that I can see...

I'm using Firefox 3.0.1 and Windows XP. What browser/OS are you running? Perhaps that might be the problem.

I'd also be curious to see what happens if you copy the code out of the include and just run it by itself.

Mark: this is on a shared hosting solution, so I can not get shell access to the file. However, as you can see here, there are no characters that shouldn't be there, and running the same file as a script does not produce this char. (The shared hosting company have been of 0 help, continually telling me it is a browser issue).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top