Aónio Aónio - 15 days ago 6
HTML Question

PHP seems to output HTML code incorrectly and with hidden characters

I have a php page. The code is:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width">
<?php include("some_file.php"); ?>
<title>Calculadora dos Custos do Automóvel</title>
</head>
<body>
<p>aaa</p>
</body>
</html>


As you can see nothing is wrong.

Though, view source of Firefox gives red erros and w3 validator gives also errors.

enter image description here

I'm around this for two days, and it is so strange. I suppose it has to do with some strange characters php might be inputting into the HTML code but I'm not sure. Or perhaps the encoding considering that the code has Portuguese characters.

Answer

As others have said BOMs are a problem when including PHP files, even if those files do not echo anything

PHP includes

At the time this article was written, if you include some external file in a page using PHP and that file starts with a BOM, it may create blank lines.

This is because the BOM is not stripped before inclusion into the page, and acts like a character occupying a line of text.

You should ensure that the included files do not start with a BOM.

in: http://www.w3.org/International/questions/qa-byte-order-mark

Detecting BOMs

You can online detect BOMs within the content of your HTML page using the W3C Internationalization Checker

Comments