##The operating environment of this article: Windows 7 system, Dell G3 computer, HTML5&&PHP version 7.1. First of all, everyone should know that HTML files with .html extension cannot parse PHP code. Only files containing HTML code with a .php extension can parse PHP code. In other words, when we want to add PHP code to the HTML code and make it parse normally, we need to change its file to a PHP file. So some novice friends may not know how to add PHP code to HTML code and parse normal data. Below we will give you a detailed introduction through a simple example.Method to add PHP code in HTML: First create a PHP file; then enter the HTML code; finally define a PHP variable and add it in the
tag, tag and
Just add PHP code to the tag. Just add PHP code to the
tag, tag and
tag.
HTML PHP code example is as follows, the file is test.php:
<?php $var = 'PHP中文网'; ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title><?php echo $var; ?> - PHP.cn!</title> </head> <body> <h3><?php echo $var; ?></h3> <p>PHP是Hypertext Preprocessor的首字母缩写,<br>是一种广泛使用的开源通用脚本语言。<br> 它是一种跨平台,HTML嵌入式服务器端脚本语言,<br>特别适合Web开发。</p> <p><a href="http://www.php.cn">跳转到<?php echo $var; ?></a>.</p> </body> </html>
Note: When embedding PHP code in HTML code, it must be complete and correct PHP code, otherwise the output variables cannot be parsed normally.
The effect of the above code when accessed through a browser is as follows: This article is about how to add PHP code to HTML and parse it normally. , it is actually very simple. I hope it will be helpful to friends who need it!The above is the detailed content of How to add PHP code to HTML. For more information, please follow other related articles on the PHP Chinese website!