Introduction to PHP programming

Sep 17, 2007 15:16 GMT  ·  By

Server side scripting is a powerful tool in the development of the present web applications. There are many scripting languages used for server side programming. PHP (PHP Hypertext Preprocessor) is the most used scripting language in the world due to the simplicity of synthax, enhanced object oriented capabilities, constant development (current version used is PHP 5) and more. The PHP code is executed by the webserver (usually Apache webserver) and the output is sent to the web browser as HTML.

This way, on the client side (your site visitor), there is not need of any plugins in order to view the php script output. PHP can be embedded in HTML also, because the server will recognize the PHP code, which usually is delimited by special PHP tags.

The PHP files are ending in .php and they can contain HTML, javascript or flash scripts. PHP applications are compatible with many operating systems. For example, the next simple PHP script allows you to display information concerning current state of PHP on your web server:

code
PHP Information Script

This is a simple HTML text displayed directly by web browser



This is PHP information
If you want to see the output of this script, save it as phpinfo.php (the file name is not important) using a text editor, then upload it to a webserver and call it in web browser. For example, in case of Windows users that have an Apache web server with PHP on their computer, they must type in the web browser address bar http://localhost/phpinfo.php, assuming that they have put the file phpinfo.php in the directory htdocs. There are some articles concerning the installation of PHP and Apache, in case you do not know how to install it on Windows.

As shown in the screenshot, you will see the text in three different colors. The text from line 7 is output by the server as simple HTML text (you can see in the web page source). The function phpinfo from line 11 allows you to view the general information regarding your PHP installation. If it is called without the argument INFO_GENERAL, it will display by default all information of your PHP installation (you can try to change the script to see the results). This simple example has an introductory scope, but PHP is more than that. With PHP you can offer your site a higher degree of interactivity for your users. You can develop interactive forms which can be used in an address book or guestbook for example. You can also create an image gallery in seconds, only by customizing an existing script, because there are many free PHP scripts that you can choose.

PHP can easily interact with databases or flat files and will help you store and manipulate information more efficiently by developing content management systems. In order to learn PHP in an efficient way it is recommended to begin with HTML and CSS first, because the functions from PHP are usually employed to output HTML content.