Once you install PHP you can try scripting a simple database to get a feel for how it works.
All the programming examples in this article work with both PHP 3 and the beta version of PHP 4.
Standard PHP scripts begin with <?php. And they end with ?>. All PHP variables start with $ just like in Perl.
Also as in Perl, there's no need to declare variables before using them. You embed all the PHP code within the HTML script, so you can use your favorite text editor to edit PHP files. There's even optional support for Microsoft's FrontPage.
You can switch between HTML and PHP scripting as much as you like within a file. For example, note the PHP mixed with HTML in the code in Listing 1, which shows how to create conditional HTML. The ereg function in line 3 of the listing does regular-expression matching on the browser identifier ($HTTP_USER_AGENT) looking to find "MSIE."
Note that the syntax of the if/else statement is identical to C's syntax. For more information on PHP functions used in the example listings, check the online PHP Manual (see Resources).Listing 1. PHP embedded within HTML generates different Web content for users with Microsoft Internet Explorer
Switching between HTML and PHP is very handy, but it is sometimes difficult to read. You could rewrite the script in Listing 1 more legibly by using the print function, as shown in Listing 2.Listing 2. This script performs the same function as Listing 1, but it's easier to read