PHP Syntax

Spread the love

In this tutorial, we will see the PHP syntax in details.To write PHP code you need to surround it using PHP tags. This will differentiate PHP code with other codes.

There are four types of PHP syntax for tags.

PHP syntaxes are as below:

  • Long form syntax –

<?php  .....  ?>

This is Most commonly used syntax. All the PHP codes can be written inside these tags.

Example:

<?php
echo "Hello from PHP."; //This will print string on browser.
?>

Output: Hello from PHP.

  • Short form (SGML style) –

<? ... ?>

This is a short form syntax. To use this syntax we have to change “short_open_tag” to “ON” in php.ini file.

Example:

<?
echo "Hello from PHP."; //This will print a string on then browser.
?>

Output: Hello from PHP.

 

  • ASP style tags – 

<% ... %>

To use ASP style tag, we have to enable “Allow ASP-style <% %> tags.” in php.ini file. This can be enable by removing semicolon before “Allow ASP-style <% %> tags.” in php.ini.

 

  • HTML script tag –

<script language="php" >...</script>

Using semicolon:

After writing all the statements, instructions, command we have to end them with a semicolon.

In further tutorials, we will see in details about the other aspects of PHP and their use in day to day programming.


Spread the love

Leave a Comment