Basic Syntax of PHP Programming Language ( Server-Side Scripting )

Basic PHP Syntax

A PHP script can be placed anywhere in the document.

A PHP script starts with <?php and ends with ?>

Syntax:

<?php

    // code comes here

?>

 

The default file extension for PHP files is ".php".

A PHP file contains HTML tags & some PHP scripting code.

Below, we have an example of a simple PHP file, with a PHP script that uses a built-in PHP function "echo" to output the text "Hello World!" on a web page:

 Example:

<!DOCTYPE html5>
<html>
    <head></head>
    <body>
        <h1>1st PHP page</h1>
        <?php
            echo "Hello World!";
        ?>
    </body>
</html> 
Note: PHP code statements end with a semicolon (;). 


PHP Case Sensitivity

Keywords in PHP (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are not case-sensitive.
 
In the example below, all three echo statements below are equal and legal.

Example:

<!DOCTYPE html5>
<html>
    <head></head>
    <body>
        <h1>2nd PHP page</h1>
        <?php
            ECHO "1st Check!";
            eCHo "2nd Check!";
            EchO "3rd Check!";
        ?>
    </body>
</html> 

 Note: However; all variable names are case-sensitive!  

 
Look at the example below; only the first statement will display the value of the $money variable! This is because $money, $MONEY, and $MoNey are treated as three different variables:
 

Example:

<!DOCTYPE html5>
<html>
    <head></head>
    <body>
        <h1>2nd PHP page</h1>
        <?php
            $money=5000M;
            echo "USA has $".$money;
            echo "UK  has $".$MONEY;
            echo "UAE has $".$MoNey;
        ?>
    </body>
</html> 
 
 
 
Comment below if you have any queries related to the above tutorial for a basic Syntax of PHP Programming Language

Post a Comment

0 Comments