Problem with whitespace before doctype

后端 未结 8 1742
迷失自我
迷失自我 2021-01-19 00:45

I got some strange problem where i have 2 copies of same website in 2 different folders. In one of those 2 copies has whitespace before doctype declaration so i have problem

相关标签:
8条回答
  • 2021-01-19 01:22

    This is especially common if you are using includes. Check over all your includes or other php files carefully that come before your output or headers.

    <?
       echo "php here"; 
    ?>
    
    This will cause a problem if it's in an includes
    that comes before your headers or doctypes. 
    Remove any non php here, file should end with "?>"
    not whitespace, linefeeds or characters.
    

    As for why? Unknown, on one production server this issue raises it's head constantly for me (CentOs 5) but on my dev machine (latest Fedora) it doesn't happen and I have no issues.

    Honestly there's probably something I could track down to find out why, but since proper usage says "no extra spaces or lines" I just do that and don't worry too much about the "why is it handled differently on my servers" all that much. (Kind of a cop-out I know)

    0 讨论(0)
  • 2021-01-19 01:23

    You don't say which browser you're having problems with. IE used to check the first few letters of the page for a doctype and, if it isn't one (such as whitespace), it would go into quirks mode.

    0 讨论(0)
提交回复
热议问题