A PHP script starts with <?php and ends with ?>. Every statement ends
with a semicolon.
<?php
echo "Hello";
echo " world!";
?>The closing tag is optional
In a file that is pure PHP (no HTML after it), leave off the closing
?>. This is the recommended style — a stray space or newline after ?>
gets sent to the browser and can break headers and cookies later.
<?php
echo "This file is pure PHP — no closing tag needed.";Case sensitivity
Keywords (if, echo, class, function) and function names are
case-insensitive. Variable names are case-sensitive.
<?php
ECHO "works";
echo "also works";
$name = "Sita";
echo $NAME; // Warning: undefined variable — different variable!Write everything in lowercase anyway; mixed case is legal but nobody does it.
echo vs print
Both output text. echo is marginally faster and can take several
comma-separated arguments; print returns 1 so it can be used in an
expression. Use echo.
<?php
echo "One", " ", "call";
print "Also fine";Knowledge Check
4 questions — test your understanding
What is the purpose of PDO in PHP?
Why use prepared statements instead of string concatenation?
What does `PDO::FETCH_ASSOC` return?
What does `try/catch` do in PHP?