How to add PHP code to HTML

藏色散人
Release: 2023-04-04 13:38:02
Original
30983 people have browsed it

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, <h3> tag and </h3> <p> Just add PHP code to the tag. Just add PHP code to the </p> <title> tag, <h3> tag and </h3> <p> tag. </p>

How to add PHP code to HTML

##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.

HTML PHP code example is as follows, the file is test.php:

<?php
$var = &#39;PHP中文网&#39;;
?>
<!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>
Copy after login

Here we define a PHP variable, and in the tag, <h3 php code has been added to the tag and> tag. </h3> <p></p> <p>Note: <strong>When embedding PHP code in HTML code, it must be complete and correct PHP code, otherwise the output variables cannot be parsed normally. </strong></p>The effect of the above code when accessed through a browser is as follows: <p></p> <p style="text-align: center;"><img src="https://img.php.cn//upload/image/230/339/984/1543457122973364.jpg" title="1543457122973364.jpg" alt="How to add PHP code to HTML"></p>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! <p></p>

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template