Inserting PHP Code


To insert bits of PHP code in an HTML page, all you have to do is insert it in a special tag, like this:

<? any amount of PHP code ?>
Note: depending on your HTML editor, or if you are using XML, you might need to use one of these alternate "PHP tags":
<?php "blah blah blah" ?>

<% "blah blah blah" %>

Here is an example which uses a variable:

<!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" lang="en" xml:lang="en">
<head>
<title> <? print($pagetitle); ?> </title>
</head>
<body>
HTML code... <? PHP code ?> ...HTML code... <? PHP code ?> ...HTML code... etc...
</body>
</html> /p>

The print statement in the "Title" line simply sends the value of the variable $pagetitle to the browser.

Let's say we had previously assigned a value to $pagetitle, by using the following expression (somewhere in the beginning of the same page, for example):

<? $pagetitle='This is my page!'; ?>
Then what the browser would receive is:
<html>
<head>
<title>This is my page!</title>
</head>

etc...
As you can see, as far as the browser is concerned, this is just HTML...






Copyright © 1999-2003. Maxis Media Studios, LLC All Rights Reserved.
Montreal Web Design - Maxis Media