Back to course

Understanding PHP Syntax and Tags

PHP: The Complete 0 to Hero Bootcamp

4. Understanding PHP Syntax and Tags

While PHP is embedded within HTML, it has strict rules regarding its own syntax.

Case Sensitivity

In PHP, variable names are case-sensitive, but built-in functions, keywords (if, echo, while), and class names are case-insensitive.

php

<?php $name = "Alice"; // $name $Name = "Bob"; // $Name (a different variable) echo $name; // Outputs Alice // Both work ECHO "<br>Using caps for echo."; eChO "<br>Using mixed case for echo."; ?>

Statements and Semicolons

Every individual statement in PHP must be terminated with a semicolon (;). Forgetting the semicolon is one of the most common beginner errors.

php

<?php $x = 10; $y = 5; $sum = $x + $y; // Must end with a semicolon echo "The sum is: " . $sum; // The final statement ?>

Note: Semicolons are not required after the closing PHP tag (?>) or after the closing brace of a block (}).

Comments

Comments are non-executable parts of the code used for documentation.

  1. Single-line comments: php

    <?php // This is a C++ style single-line comment # This is a shell-style single-line comment ?>
  2. Multi-line comments: php

    <?php /* This is a comment block that spans multiple lines */ ?>