我是否需要在html文件中使用!DOCTYPE声明? [英] Do I need a !DOCTYPE declaration in a php file with html?

查看:109
本文介绍了我是否需要在html文件中使用!DOCTYPE声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含我的网站内容的php文件。该文件需要.php,因为我先获得一些变量,然后在网站内容中使用它。像这样的例子:

 <?php 
$ user_name = $ _REQUEST ['username'];
?>

<!DOCTYPE HTML>
< html>
< head>
< meta charset =utf-8>
< title>页面标题< / title>
< link rel =stylesheethref =css / style.css/>
< / head>
< body>
欢迎<?php echo $ username;?>
< / body>
< / html>

我需要<!DOCTYPE HTML> ,因为文件扩展名是php?另外,它是否正确放置?它应该在标签之前还是在我的文件的第一行?

我还注意到,如果我删除<!DOCTYPE HTML> ; ,我的一些css代码停止工作......



非常感谢。

解决方案

是的,您需要一个DOCTYPE,因为您的浏览器只能看到以上代码的以下部分:

 <!DOCTYPE HTML> 
< html>
< head>
< meta charset =utf-8>
< title>页面标题< / title>
< link rel =stylesheethref =css / style.css/>
< / head>
< body>
欢迎使用者名称
< / body>
< / html>

我通常将关闭PHP标签和DOCTYPE放在一起,就像?> ;<!DOCTYPE HTML>


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:

<?php
$user_name = $_REQUEST['username'];
?>

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>Page Title</title>
    <link rel="stylesheet" href="css/style.css" />
</head>
<body>
Welcome <?php echo $username;?>
</body>
</html>

Do I need the <!DOCTYPE HTML>, since the file extension is php? Also, is it placed corretly? Should it come before the tag or in the very first line of my file?

I also noticed that if I remove the <!DOCTYPE HTML>, some of my css code stops working...

Thank you very much.

解决方案

Yes you need a DOCTYPE as your browser only sees the following part of the above code

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>Page Title</title>
    <link rel="stylesheet" href="css/style.css" />
</head>
<body>
Welcome THE USER NAME
</body>
</html>

I usually place the close PHP tag and the DOCTYPE together like so ?><!DOCTYPE HTML>

这篇关于我是否需要在html文件中使用!DOCTYPE声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆