Do I need a !DOCTYPE declaration in a php file with html?

前端 未结 10 1121
面向向阳花
面向向阳花 2020-12-15 03:16

I have a php file with my website content in it. The file needs to be .php because i get some variables first and then use it later in the website content. Like this example

10条回答
  •  时光说笑
    2020-12-15 03:46

    Sorry to resurrect the dead, but no one seems to explain why you need a doctype in HTML (yes a PHP script outputting HTML is an HTML file at the end).

    Declaring a doctype affects the way the browser interprets your HTML (this is probably why your css code may stop working without a doctype). Basically there's 2 ways: quirks mode and strict mode. The latter is sticking to standards, so you should always tell the browser which HTML standard your code is following (nowadays you probably want HTML5 which has the simplest doctype: ).

    See here for a more detailed explanation.

提交回复
热议问题