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 { }.
<?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:
$colorand$Colorare different. - Keywords and function names are not:
ECHO,echoandEchoall work — but always write them in lowercase.
<?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?
YesNoOnly in PHP 8
Show answer
Answer: Yes