PHP Syntax

In this chapter, we will teach you syntax on the PHP. The PHP script is executed on the server and the plain HTML result sent back to the browser.

Basic PHP Syntax

You can placed PHP script anywhere in the document. A PHP code start with  <?php and end with ?>. It is also known as Canonical PHP tags.

<?php
    //Enter code here
?>

 

Another way to placed PHP Script Code. A PHP code start with  <? and end with ?>. It is also known as Short-open PHP tags.

<?
    //Enter code here
?>

 

PHP files have extension ".php"

PHP files normally contains HTML tags, and some PHP code.

Example:

<html>
  <head>
	<title></title>
  </head>
  <body>

	<?
		//Enter code here
    ?>

  </body>
</html>

 

Note : PHP statements are terminated by semicolon (;).

Example: 

<html>
  <head>
    <title></title>
  </head>
  <body>

   <?
     echo 'Hello Coders'; //PHP statement end with semicolon
   ?>

  </body>
</html>

The closing tag of a block of PHP code also automatically implies a semicolon.