html - Why is PHP moving everything from the <head> tag to the <body> tag? -


i don't know how explain this, best can show examples.

1: html - dom

<html>     <head>         <title>my webpage</title>     </head>     <body>         <section id="main">             <span>lorem ipsum dolor sit amet.</span>         </section>     </body> </html> 

good! everything's working in #1. however, when add php code...

2: html/php - dom

<?php     include_once($_server['document_root'] . "/classes/main.php"); ?> <html>     <head>         <title>my webpage</title>     </head>     <body>         <section id="main">             <span>lorem ipsum dolor sit amet.</span>         </section>     </body> </html> 

for reason, including file moved in <head> tag <body>. also, there's 2 new lines in <body> that's putting annoying space between top of window , content.

why happening?

the problem because of include_once() or include().

when save page utf-8, special signature called byte-order mark (or bom) included @ beginning of file, indicating utf-8 file. can see boms low level text editors (such dos edit). need remove signature included file in order rid of white space @ top of page.

you can solve problem doing following:

$file = file_get_contents('header.php'); $file = substr($file, 3, strlen($file)); echo $file; 

by doing avoid character.

or

in notepad++ can change encoding of file "utf-8 without bom" "encoding" menu.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -