Rules for PHP Syntax

 Rules for PHP Syntax

The main syntax rules are :

  1. All the PHP code in a PHP script enclosed within <?Php and ?> (Canonical PHP tags every expression in PHP ends with a semicolon ;
  2.  The default file extension of PHP files is ".php".
  3.  Commenting PHP code:

  • Both single-line and multi-line comments.
  • For single-line comments, use # or // before the comment line. For example,

<?Php

 # This is also a single line comment

// This is a single line comment

            ?>

For multi-line comments, use /* ... */.

Example:-

<?Php

            /*

                       This is also a single line comment */ ?>

 

4. Case Sensitivity

  • In PHP, keywords, classes, functions, and user-defined functions are not case-sensitive.

<?Php

                        Echo "Hello, World!";

                        ECHO "Hello, World!";

?>

Output:-

Hello, World!

Hello, World!

5. All variable names are case-sensitive.

           Example:- variable $abc is not the same as $Abc, represent as two different variables in PHP.

 6. Curly braces use to define a code block.

 

<?Php

    If($zero == 0)

    {

        Echo "If code block";

    }

?>

5.    7. Constant is defined by the const keyword or define() function.

6.    8. Dollar sign($) symbol used before the variable name.  

7.    9. Use only alphanumeric characters and underscores([ a-z0-9_ ]) for variable and 

           function names. (Never begin a variable or function name with a number).

8.    10. Not use any Reserved Words name as a variable name.

9.    11. Not require data types before variable declarations this method call Dynamically

               Naming Variables.

12.  PHP is insensitive to whitespace. All types of spaces(tabs, spaces, and carriage returns) are invisible on the screen.

13. Semicolon(;) use for Terminates Lines and Statements.

14. Use the period(.) To concatenate(join strings or append variable data into strings).

15. Escaping Quote Marks With Backslash If use double quotes to encapsulate our string must escape any double quotes that need to reside in the string.

16.  @ symbol use for  Error Suppression Character ( before certain expressions), used to suppress any error messages that the expression may generate.

===========================================================

Post a Comment

0 Comments