Introduction to PHP Learning Guide
PHP is a significant language, with millions of practical applications used for a variety of commercial and non-commercial purposes. It is installed on thousands of web servers worldwide, and web hosts consider using PHP on their servers for other applications e.g. hosting control panels. Due to the greatly increased availability over other web languages (Perl for instance), PHP has grown rapidly and knowledge of it can even lead to a high paying job. However, today we're going to start out small and teach you the basics, step by step, of the Wikiversity Introduction to PHP.
For PHP to run, this web server has to be configured so that when certain requests come - requests for pages with the .php extension, for example - PHP is called. The php.exe file then jumps in, looks at the code, interprets it and sends the output back to the web server within a fraction of a second for the web server to send back to the client. This means that if your PHP code was the following:
<?php echo "ABC"; ?>
All that would be sent to the user's web browser is this:
This means that significant web applications can be developed by software firms without having to worry about competitors stealing their code - after all, you wouldn't want to spend millions only for your arch rivals to get it all for free by taking it from your servers.
As this is your first PHP lesson, we'll cover this section in detail. How web servers handle programming languages is quite simple - they look for certain file extensions (the .whatever in the file name) and run specific commands depending on the file type. In this instance, web servers look for .php in the file name, and instead of simply sending the file across, they call a program called php.exe and pass the file to it. php.exe then parses (interprets) it before sending the output back to the web server.
However, there is a very useful feature of PHP that requires some further insight here. This feature is PHP's ability to effectively jump in and out of 'PHP mode', so that, at times, normal HTML can be used in scripts. This is a basic example:
<html> <body> <?php ?> </body> </html>
Notice that normal html tags are wrapped around the php. If this were a .html file, what would be sent to your web browser is exactly the above.