HOME HTML EDITOR C JAVA PHP

PHP Basic Syntax

A PHP script can be placed anywhere in the document. It always starts with the opening tag <?php and ends with the closing tag ?>.

1. PHP Tags Example

Anything written inside these tags is treated as PHP code by the server:

<?php
  echo "This is a PHP statement";
?>

2. Case Sensitivity

Keywords like echo, if, and while are not case-sensitive. However, Variables are strictly case-sensitive.

<?php
  echo "Hello"; // Valid
  ECHO "Hello"; // Also Valid

  $user = "Admin";
  echo $user; // Outputs: Admin
  echo $USER; // Error: Variable is undefined
?>

3. The Semicolon (;)

Every PHP instruction must end with a semicolon. Forgetting this is the most common cause of "Parse Errors".

<?php
  echo "Line one";
  echo "Line two";
?>

4. Comments

Comments are used to leave notes for yourself or other developers. They are ignored by the server.

<?php
  // Single-line comment
  # Another single-line comment
  /*
    Multi-line comment block
    useful for long explanations
  */
?>