PHP Syntax | PHP tutorial | Learn PHP

As we have discussed in earlier sections that PHP and HTML codes can be written in a same file, so there there needs a way with which we can separate PHP code from other code blocks. This is where PHP Syntax come into play.

The PHP can be embed in within HTML with different methods. Some of them are available by default and some needs to be enabled using PHP’s configuration file that is php.ini.

Canonical PHP Tags (PHP Syntax) –

This is the most common and widely used method to embed PHP tag within a document. In this the PHP Syntax, script starts with <?php and ends with ?> .

Make sure you always close the PHP tag after you’re done with your script, otherwise you’ll get errors.

In order to insert HTML code between PHP you can either use echo statement or you can close your PHP before inserting HTML code and then start your PHP again.

SGML or short HTML tags –

This is the shortest method to define PHP within a document. In this the PHP starts with <? and ends with ?>. To use this method, short_php_tag option needs to be enabled in php.ini file.

Every PHP statement needs to be end with semi-colon(;), it is also known as delimiter as it represents the end of statement.

Case Sensitivity in PHP

All the functions, keywords and class names in PHP are NOT case sensitive, but the variables in PHP are case sensitive

For example, $a and $A are treated as two different variables in PHP.

Author: Deepak Kumar

This is Deepak Kumar, founder of True Infosystems and of-course the chief content creator at CodingLessions.info. Started my carrier as a Freelancer and now a top-rated Freelancer at Upwork, delivered over 200 successful projects with highly positive user ratings and counting.