How PHP Files Are Processed

chinmay.sahoo

New member
It is conventional for an HTML fi le to be given a name with the fi le extension htm or html, e.g. mypage1.htm. However most (if not all) browsers will accept any (reasonable) extension, e.g. mypage1.xyz. If the fi le extension chosen is php we will call the fi le a PHP fi le instead of an HTML fi le. Having a fi le name with extension php enables a fi le to be processed by the PHP interpreter (on the server) as well as the user's web browser. A PHP fi le can contain any of the following:


• Nothing but HTML (i.e. it is just an HTML fi le with a php fi le extension). This is unusual but possible.
• A single PHP script with no HTML.
• One or more (generally short) PHP scripts, which can be placed anywhere in the fi le, including at the beginning and/or at the end, the remainder of the fi le being HTML. Such short scripts are often called scripting blocks .

Each PHP scripting block begins with the fi ve-character combination

<?php
and ends with the two-character combination
?>


These are called the opening PHP tag and the closing PHP tag , respectively. The effect of pointing a web browser at an HTML fi le has been explained previously. When a web browser points to a PHP fi le, the fi le contents are assumed to be HTML and the same sequence of actions is performed as before. However if the web server fi nds an opening PHP tag then rather than sending the character stream to the web browser as usual it sends everything from the opening PHP tag to the next closing PHP tag to the PHP interpreter (which is located on the server). The PHP interpreter treats everything between the tags as a sequence of PHP statements (also called instructions) and processes them one by one. (This is called 'executing the script' or 'executing the statements'.)
 
Back
Top