Here is the basic hello world program in PHP from the PHP manual 35.
The first five lines in the script are HTML tags. The
PHP bit starts on the sixth line. The syntax <?php
tells the PHP processor to start processing a script. The script in this
case is the line
This script is executed by the PHP processor on the server.
The output of the script is the HTML page with the "Hi, I'm a PHP
script!" inserted in the place of the <?php... ?>. .
The script looks like this screenshot in a browser.
To use PHP your web server has activated support for PHP and that all files ending in .php are handled by PHP. On most servers, this is the default extension for PHP files. Popular Linux distributions, such as Red Hat, and popular ISP hosting services will have this configured by default. For the example above, save the file as hello.php and put it in any public directory on your web server.
Here is a useful program to print out the server environment to a HTML page:
This will print out a long list of server information beginning with this screenshot:
Getting started with HTML forms is very easy with PHP
Here is simple example that shows how to process a basic
form. The form page is straight HTML.
This prompts the user to input his or her name and posts to a PHP page called simple_form_processor.php. A screen shot is shown below.
The PHP script that processes the post request checks to see if the user's name is 'Alex'.
The result is shown in the screen shot below.
The value of the user ID is retrieved with the $_POST['name']
variable an used in an if statement. If statements in PHP have
the same syntax as Java and C. The use of a semicolon is also
similar to Java and C. However, for the last statement in a block
the semicolon is optional.
There are no user comments.
Please send ideas and opinions by email at alexamies@gmail.com.