PHP Logo

PHP Section


PHP is a scripting language to create web pages with dynamic content. PHP can be embedded into HTML and therefore easily integrated with the existing technologies to create homepages. PHP has libraries which provide fast and customizable access to DBMSs, Database Management Systems. There are more explanations for the acronym PHP, but the most common one is that its a recursive abbreviation and that it stands for PHP Hypertext Preprocessor. The word Preprocessor already tells what a PHP engine does: it processes the information necessary to display a certain page and displays the page according to the conditions created by that information.

PHP started as an extension on the existing Perl/CGI engines available on many web servers. With additional libraries it is possible to make an existing Apache Web Server support PHP. If a PHP file is requested via HTTP it will be parsed by the PHP engine and the result of that action will be served by Apache as an HTML file to the requester. In that way any regular browser will be able to render the result as a regular HTML page. The PHP engine doesn't really care about the HTML that is outputted, so it is possible to use all existing and additional techniques such as CSS and JavaScript and integrate them with the pages which are generated by the PHP engine.

The source of a simple PHP page looks like this:

<html>
<head>
<title>PHP Test - Hello World</title>
</head>
<body>
<?php echo "<p>Hello World!</p>"; ?>
</body>
</html>

Note that the code between <?php  and ?>  actually is PHP code. This code will be executed by the PHP processor before the page is served when a request to that particular page is made. The result of the execution is combined with the other (static) parts of the page and is sent to the requester. The code outside the PHP block is HTML. So it is easy to integrate the PHP code into an HTML page. The only condition is that the web server on which this page will be placed supports PHP and is able to parse PHP templates. Most servers supporting PHP require that each PHP file is saved with the exstension .php, but the server can be configured in such a way that this is not particulary necessary.

When the code in the example above would be saved in a file called for instance hello.php on a web server that is able to parse PHP templates and that page would be requested by a browser, the browser would display the text Hello World!, because the following HTML would be be sent back to that browser:

<html>
<head>
<title>PHP Test - Hello World</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>

The PHP parser would parse the code within the PHP block. The echo function writes output to the stream of data that will be sent back to the requester. Easier said: the echo function writes back output to the screen of the requester of the page. So the code between the quotes ( "  ) will be written by the echo function. Note that each programming line in PHP ends with a semicolon ( ; ). This is just like in many other programming languages such as Java, C/C++ and Pascal. This means that any person who writes PHP pages has to be very careful not to leave out any semicolons otherwise the page will not be served and errormessages will be displayed when a request for that page is made.

Links

See Also

Contact the author: Send an electronic mail to: pajtroon@dds.nl.
Peter's ICQ Number is: #3900785.

This page: Copyright © 2002 - 2005 Peter A. J. Troon

Note: This page is part of the Peter Troon Site.