setup, which defines when PHP can be invoked, is held in your Web server's
configuration file (srm.conf on Apache). Failing that, you will need to study the
PHP documentation.
What happened here? It's a plain HTML page, except for two important things: one is the filename
extension (.php3), and the other is the lines between the <?php and ?> tags. These are special tags
denoting a section of PHP script. You'll look a little more into invoking PHP in a moment.
The echo command is PHP-speak for print to screen. In the example, it displays the text in quotes,
together with the system time since 1970 in seconds. Rudimentary stuff this may be, but you've just built
your first PHP-enabled dynamic Web page.
How PHP Works
When a request comes into a PHP-enabled Web server from a client's browser, the Web server does a
number of things:
It receives and reads the request from the client browser.
It locates the requested page on the server.
It executes any instructions given by the embedded PHP code, unlike a normal HTML
page.
It sends the resultant page to the client.
Now that you have a grasp of the basic principles of PHP, you'll take a look at the language in more
detail. After that, you'll learn how PHP can help you make the users of your Web site interact with a
MySQL database.
A Quick-Start Guide to PHP
Here's a guide to the PHP language, designed to get you started quickly. To keep it lightweight, it's assumed
that you're comfortable with the basic principles of coding, and that you're comfortable writing simple HTML
pages. Included is a useful but non-exhaustive set of PHP syntax. It's designed more to whet your appetite
than to be a reference manual but, nevertheless, you should be able to compile quite sophisticated dynamic
Web pages after digesting it.
Basic Syntax
PHP requires escape codes to indicate where your HTML file flips into PHP mode. You can use any of the
following tags around your code (an echo statement is given as example):
<?php
echo "PHP mode now";
?>
or
<? echo "PHP mode now with short tags"; ?>
or
<script language="php"> echo "PHP mode now"; </script>
You can use multiline or single-line forms, no matter which tag style you choose.
The second option is the easiest (using just <? and ?>, it's shortest!) but requires you to enable "short
tags" (these may already be enabled, depending on your installation). The third may make life easier
with certain WYSIWYG HTML editors, which don't like unusual tags.
An important thing to notice here is that there is a semicolon (;) after every PHP statement. This is the
end-of-statement character. This is essential. However, PHP doesn't mind if you put several statements
on one line or spread one statement across several.
Types
PHP supports integers, floating-point numbers, strings, arrays, and objects. When PHP accesses a variable,
it decides which type to use it as, according to the context in which it is used. It can even use the same
variable as different types—this is known as type juggling. Variable types are usually not set by the
programmer (there's often no need, although it can be done).