PHP Syntax and Tags | PHP for beginners

The PHP syntax is a set of rules that define how to write a PHP program properly. PHP has no different from any other language. The PHP interpreter checks every line and returns an error if you do not follow the syntax properly.

We can use four different pairs of opening and closing tags in PHP.

  • Default syntax
  • Short open Tags
  • Omit the PHP closing tag at the end of the file

PHP Default Syntax

Default syntax of PHP starts with “<?php” and ends with “?>“.

Syntax :

<?php
  //Your Code here
?>

By default the extension of PHP is .php

Short Tags

The PHP short tags start with “<?” and ends with “?>”

Example:

<?
echo "This is PHP short tags example";
?>

Omit tag at the end of the file

It’s better to omit the tag at end of the file if you using only PHP code on your webpage. Omitting PHP tag at end of the file will reduce the errors of whitespaces.

Example:

<?php
echo "This is PHP omit tag example";
?>

PHP Case sensitivity

In PHP the user-defined functions, classes are case-insensitive. Check out the below example for better understanding.

Example for case sensitivity :

<?php
echo("First PHP case sensitivity <br />"); 
ECHO("Second We are learning PHP case sensitivity <br />");
EcHo("Third PHP case sensitivity <br />");
?>

Output :

First PHP case sensitivity

Second We are learning PHP case sensitivity

Third PHP case sensitivity

Separating the PHP statements

Like many languages, PHP statements also terminated with a semicolon(;). If you are in the last line of your PHP code no need to add a semicolon(;).

  • a semicolon
  • AND/OR
  • a closing PHP tag

Posted in PHP

One Reply to “PHP Syntax and Tags | PHP for beginners”

  1. Hello there, I do think your website could possibly be having internet browser compatibility
    issues. Whenever I look at your web site in Safari, it looks fine however, when opening in Internet Explorer, it’s got some overlapping issues.
    I just wanted to give you a quick heads up! Other than that, great website!

Leave a Reply

Your email address will not be published. Required fields are marked *