How to Write PHP Code?
A PHP script starts with <?php and ends with ?>.
It can be placed anywhere in the program.
First we will start with a simple PHP code to print “This is my first PHP program”.
The extension of the file is given as .php.
<?php echo “This is my first PHP program.”?>
Result: This is my first PHP program.
Note: echo is used to give the output.
Comments in PHP
A comment is the portion of aprogration which only meant for human reader.Its only purpose is to read by someone who is looking to your program.
Comments can be used to:
1- Let others understand what you are doing
2- Remind yourself what you did.
# This is single line cmment
// This is also single line comment
/* This is multi lines comment
Purpose:Multi lines Comment*/
PHP is Case sensitive
Yes PHP is case sensitive. Try Out yourself:
print(“Variable capital is $text<br>”);
print(“Variable capital is $Text<br>”);
Variable capital is 50
Variable capital is
In PHP echo and print both are used to display output.Both of them more or less are same.
The main difference between echo and print is that:
Echo does not return any value but print return value 1 in expression. Let’s see some examples:
Display text using echo:
echo "Hello world!";
Display Variable using echo
echo $a+ $b;
Display text using print:
print "Hello world!<br>";
Display Variable using print:
print $a+ $b;