Basic Syntax in PHP



In this tutorial, we will learn the basic syntax of PHP language. We will go through the key components of a simple PHP program.

PHP Program

<?php

echo "Hello, World!";

?>

Output

Hello, World!

Basic Syntax of a PHP Program

  1. <?php
    This opening tag indicates the start of a PHP code block.
  2. echo "Hello, World!";
    This line uses the echo statement to output the string "Hello, World!" to the browser or standard output.
  3. ?>
    This closing tag indicates the end of a PHP code block.

Key Points to Remember

  • All PHP statements must end with a semicolon (;).
  • PHP code is typically embedded within HTML using tags like <?php and ?>.
  • Comments can be added using // for single-line comments or /* ... */ for multi-line comments.
  • PHP is case-sensitive, meaning that echo and ECHO would be considered different.