|
Introduction to PHP ProgrammingHomeThe full form of PHP is "PHP : Hypertext Preprocessor". It is a server side scripting language used for dynamic webpage generation. The meaning of server side technology is that all processing which is necessary is done by the server which hosts the PHP script, and the processed HTML output is given to the client. This is in sharp contrast to languages like JavaScript, where the processing is done at the client side. PHP code is embedded in the HTML page itself, with the help of special tags, that we will see in a short while. There are a number of advantages of using a server side technology like PHP. The main advantage is that, all compatibility problems between various browsers gets eliminated. The reason for this is that, the server must support PHP scripting, the client would only get standard HTML code, which every web browser supports. This is the reason why PHP is more suited for older browsers at the client side. Also, because the client gets only the processed HTML code, it automatically prevents script-theft. Of course, PHP is not without its share of disadvantages also. Some amount of configuration has to be done to the webserver for PHP scripts to work. This may also include adding and installing new packages. Also since all processing is done by a single server, which hosts the PHP script, a large number of client requests may overburden the server. We now start looking at PHP code. This assumes, you have configured your webserver appropriately. To differentiate between normal HTML files and PHP script files, the latter are given extensions like .php, .php4 and .phtml. Now open up any text editor and write :- <HTML> Now save it as 'hw.php' in your webserver directory. Now notice that you gave this file and extension of .php. So your PHP engine at the server side will process this code, and give the client a pure HTML code like :- <HTML> To view the output of this file, start your web-browser and type :- and you should get the required result. A keypoint here is that PHP code is embedded inside special tags - <? and ?>. Now by editing the php.ini file, it is possible to replace these tags, by ones which you are more comfortable with, but for educational purposes, in this tutorial, all PHP code will be placed between the tags - <? and ?>. A variable is a memory space which can store any possible value in its domain. Its name is usually chosen by the programmer himself. This value can change during the execution of the program, unlike constants. In PHP, variable names should start with a '$' sign. The names can include uppercase and lowercase letters, digits and underscores. But it is not possible to include spaces or other special or reserved characters to define the names of a variable. Also since PHP, is a case sensitive language, particular care has to be taken while writing variable names in different cases. For example, $num and $NUM are two different variables with the same name but different cases. We now look at another code snippet :- <HTML> The output of this code snippet will be :- Genius : Albert Einstein This is very important to remember while doing PHP
programming, anything between double quotes, undergoes required
conversion, but anything within single quotes is treated as it is. This is
again in sharp contrast to normal programming conventions. Written by Rahul Batra Special thanks to Bhavana Singh |