PHP is a tool that lets you create
dynamic web pages. PHP-enabled web pages are treated just like regular HTML
pages and you can create and edit them the same way you normally create
regular HTML pages.
What do I need?
In this tutorial we assume that your
server has support for PHP activated and that all files ending in .php3
are handled by PHP. On most servers this is the default extension for PHP
files, but ask your server administrator to be sure. If your server supports
PHP then you don't need to do anything. Just create your .php3 files
and put them in your web directory and the server will magically parse them
for you. There is no need to compile anything nor do you need to install
any extra tools. Think of these PHP-enabled files as simple HTML files with
a whole new family of magical tags that let you do all sorts of things.
Your first PHP-enabled page
Create a file named hello.php3
and in it put the following lines:
<html><head><title>PHP Test</title></head>
<body>
<?php echo "Hello World<P>"; ?>
</body></html>
|
The colours you see are just a visual
aid to make it easier to see the PHP tags and the different parts of a PHP
expression. Note also that this is not like a CGI script. The file does
not need to be executable or special in any way. Think of it as a normal
HTML file which happens to have a set of special tags available to you that
do a lot of interesting things.
This program is extremely simple
and you really didn't need to use PHP to create a page like this. All
it does is display: Hello World
If you tried this example and it
didn't output anything, chances are that the server you are on does not
have PHP enabled. Ask your administrator to enable it for you.
The point of the example is to show
the special PHP tag format. In this example we used <?php to
indicate the start of a PHP tag. Then we put the PHP statement and left
PHP mode by adding the closing tag, ?>. You may jump in and
out of PHP mode in an HTML file like this all you want.
|