Search code examples
javascriptphphtmlcsshead

Head tag in html page closes programatically after page load


My page is located here As you can see, it doesn't look like it's working properly. This becomes very apparent if you try to open it in an older browser (this is what initially set me off).

I checked the interpreted source code from chrome and it shows me the following:

<html>
    <head>
        <style type="text/css"></style>
    </head>
    <body>
            <title>Internet adgang - Hurtig opsætning - Ansatte</title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">

Etc..

Something seems to be closing my head tag which is causing all SORTS of errors:

W3 validator

I have absolutely no idea what is causing this.

You can see my source code here (I've scrambled the PHP):

The code above does not contain my body code, as I am fairly sure that has nothing to do with the head tag closing all of a sudden.

Here is some source of a page that works just fine:

I am completely baffled by this and I have no idea what to do nor what is causing it. Any ideas?

Solution

With the help of Buttc4k3 and vogomatix I finally found the solution. As buttc4k3 said, there was an illegal "zero-width no-space" character hidden in the file which didn't show in my sublime text editor. It would only show if you opened the file in Notepad++. I could not understand why this character would appear in google chrome, and not in my source, but after googling it, I found that a file saved in UTF-8 WITH BOM (Byte Order Marking) would save the BOM as a zero-width no-space character! This was where vogomatix saved me and told me that my file was saved with BOM and after recoding it without BOM it works fine.

So - if you have the same problem as me - save your file WITHOUT BOM ENCODING (this can be done in notepad++).


Solution

  • I took the page source of your website and pasted it in Notepad++ and found a zero-width no-break space in line 3 column 5. It renders invisible in most editors/viewers, but it breaks the HTML parser of the browser. I don't know how or why it got there since I can't find it in the PHP code, but maybe you can find it by opening your code in Notepad++. It renders this character as a tiny dot. If you can't find it, delete everything from and including <head> to <title> and re-type it.

    I hope this works.

    PS: Even though it is not the reason why your page is broken, you should add <html> and </html> to the markup. Most browsers can deal with its absence, but it is there for a reason.