Adding PHP to HTML
From Wiki
How does the PHP parser recognize PHP code inside your HTML document? The answer is that you tell the program when to spring into action by using special PHP tags at the beginning and end of each PHP section. This process is called escaping from HTML or escaping into PHP.
At any given moment in a PHP script, you are either in PHP mode or you are out of it in HTML. Anything within the PHP tags is PHP; everything outside is plain XHTML, as far as the server is concerned. You can escape into PHP whenever you consider that is necessary.
For example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login</title>
</head>
<body>
<?php $id = 1; ?>
<form method="post" action="registration.php">
<p>First name: <input type="text" name="firstname" size="20" /></p>
<p>Last name: <input type="text" name="lastname" size="20" /></p>
<p> Rank:
<input type="text" name="rank" size="10" />
<input type="hidden" name="serial number" value="<?php echo $id; ?>" />
<input type="submit" value="INPUT" />
</p>
</form>
</body>
</html>
Notice that things that happened in the first PHP mode instance-in this case, a variable being assigned-are still valid in the second (the $id variable). Below is a basic example of a registration.php file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Register</title>
</head>
<body>
<p>Welcome <?php echo $_POST['firstname'] ?> <?php echo $_POST['lastname'] ?>! </p>
</body>
</html>
See also: Including PHP in HTML, PHP Templates
