html中能不能写php

小编给大家分享一下html中能不能写php,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

html中可以写php吗?

html中可以写php代码,但是文件后缀名需要是.php而不是.html。否则php程序不会被解析执行。

1、新建一个index.php文件,像书写html一样,写上基本标签。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
    <p>这是html</p>
</body>
</html>

2、然后在html代码中插入php代码片段,例如:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
    <p>这是html</p>
    <?php echo "hello"; ?>
</body>
</html>

3、打开网页即可看见效果:

html中能不能写php

看完了这篇文章,相信你对html中能不能写php有了一定的了解,想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!