First PHP Program
We will start with a simple Hello World Program.
<?php echo “hello world!!!”; ?>
You can see the output of the file by clicking try now.
This code prints hello world!!!. Let's understand the code line by line
<?phpis for the initiation of PHP code. You may not understand the significance of this here but it is extremely useful while embedding PHP in HTML code.
echo “hello world!!!”;
echois a function which prints value give to it, Here it is printing a string.
echonot only prints string, it prints anything which is printable.
;acts as instructions seprator. You must use
;after ending of each statement or you will face error.
?>denotes ending of php code. It may be temorary i.e. it is possible that there is more PHP code in the file which will be started using
This will come handy while creating dyanamic webpages where we may need to use PHP code at multiple places in single webpage.
You will be able to understand this better with this code
<!DOCTYPE html> <html> <h1><?php echo "title"; ?></h1> <p><?php echo "description"; ?></p> </html>
Here we have ended PHP code in line 3 with
?> and code is again initiated in line 4.
Comments in PHP
Single line comments can be added in PHP code using
#. Multiple line comments are added using
/* comments */ Here is a code demonstrating comments in PHP
<?php //Here is a single line comment # There goes another comment echo "title"; /* Want to see a multiline comment as you wish */ ?>