- PHP code is interpreted by a web server with a PHP Preprocessor module which generates the resulting HTML.
- The client browser only receives HTML.
- PHP script always starts with <?php and ends with ?>.
- PHP script can be placed anywhere in the document.
- In some server you can use the above script as <? and ends with ?> but it does not support by all servers.
- Normally PHP file contains HTML tags and PHP scripts.
- PHP file must be stored in .php file extension
- Each PHP code must end with semicolon(;)
Sample PHP coding
<html> <head><title>Sample PHP</title></head> <body> <?php echo "I am learning PHP from s3learn.com"; ?> </body> </html>
Data Received by the Browser:
<html> <head><title>Sample PHP</title></head> <body> I am learning PHP from s3learn.com </body> </html>
Comments in PHP
- // for single line comments.
- /* some text block */ for comment block.
<html> <body> <?php //This is single line comment /* This is multi line comment block */ ?> </body> </html>