PHP Tutorial · PHP Basics · Lesson 3 of 38

PHP Syntax

Tags, statements, semicolons and case sensitivity rules.

Statements end with semicolons

Every PHP statement ends with ;. Blocks use curly braces { }.

Example 1Try it yourself
<?php
$name = "PHP";
if (strlen($name) === 3) {
    echo "Three letters!\n";
}
echo "Done\n";

Output

Three letters!
Done

Case sensitivity

  • Variable names are case-sensitive: $color and $Color are different.
  • Keywords and function names are not: ECHO, echo and Echo all work — but always write them in lowercase.
Example 2Try it yourself
<?php
$color = "red";
$Color = "blue";
echo $color . " " . $Color . "\n";
ECHO "keywords are case-insensitive\n";

Output

red blue
keywords are case-insensitive

Whitespace and newlines

Extra spaces and line breaks don't matter to PHP. To output a new line in text, use "\n" (or PHP_EOL) inside double quotes; in HTML output use <br>.

Test yourself

Are PHP variable names case-sensitive?

  1. Yes
  2. No
  3. Only in PHP 8
Show answer

Answer: Yes