PHP Syntax and PHP Comments
In this PHP tutorial first we start PHP Syntax after that we start PHP Comments.
Let’s Start PHP Syntax
- A PHP code starts with
<?php
and ends with?>
. - This PHP code can be placed anywhere in the document.
- PHP codes file save with
.php
extension.
A syntax of PHP tag is given below:
welcome.php
<?php // PHP Script written here!; ?>
Let’s see below, we assume an example of a simple PHP file, with a PHP code that uses a PHP function echo to output the text “Welcome to My First Class in PHP Tutorial !” on a web page:
welcome.php
<!DOCTYPE html> <html> <body> <h1>My first PHP page</h1> <?php echo "Welcome to Netzole PHP Tutorial !"; ?> </body> </html>
Every PHP statement end with a semicolon (;)
Case Sensitivity
In PHP all variable names and function and classes names are case-sensitive. See given below examples.We assume three variables $car, $Car and $CAR.
Example
<?php $car= "BMW"; $Car= "Mercedes"; $CAR= "Audi"; // Try to print variable value echo "The car model is " . $car. "<br>"; echo "The car model is " . $Car. "<br>"; echo "The car model is " . $CAR. "<br>"; ?>
Output:
The car model is BMW
The car model is Mercedes
The car model is Audi
Let’s see another examples:
<?php <!DOCTYPE html> <html> <body> <?php ECHO "Good Morning!<br>"; echo "Good Morning!<br>"; EcHo "Good Morning!<br>"; ?> </body> </html>
PHP are case-sensitive. It’s mean ECHO, echo and echo generate the same result, which is given below:
Good Morning!
Good Morning!
Good Morning!
PHP Comments
So now we start second part PHP Comments. PHP Comments are those comments which is used to describe any single line of code so that other programmers can understand the code easily. It can hide any PHP scripts.
There are two types of PHP Comments which is describe below:
1. Single Line Comments
There are two option to use single line comments in PHP.
- //
- #
<!DOCTYPE html> <html> <body> <?php // This is a single line comment # This is also a single line comment echo "Good Morning!<br>"; ?> </body> </html>
Output:
Good Morning!
2. Multiple Line Comments
<!DOCTYPE html> <html> <body> <?php /* This is a multiple lines comment block This is a multiple lines comment block This is a multiple lines comment block */ echo "Good Morning!<br>"; ?> </body> </html>
Output: