Beginner Fundamentals
PHP Syntax
PHP code follows a simple set of rules. Understanding the basic syntax helps you avoid common errors from the start.
PHP tags
All PHP code goes between an opening <?php and a closing ?> tag.
<?php
echo "Inside PHP tags";
?>
If a file contains only PHP, you can omit the closing tag, which is a common practice.
Statements and semicolons
Each statement must end with a semicolon ;. Forgetting it causes a syntax error.
<?php
echo "Line one";
echo "Line two";
Case sensitivity
Variable names are case sensitive, so $name and $Name are different variables.
<?php
$color = "blue";
echo $color; // blue
echo $Color; // Error: undefined variable
Keywords and function names are NOT case sensitive, so ECHO and echo both work. Still, prefer lowercase for consistency.
<?php
ECHO "This works too";