Before going any further, it's worth nailing down the small rules that every single PHP file follows, so they stop being a distraction once real logic starts.
PHP code always lives between <?php and ?>. Everything inside those tags is executed as PHP; everything outside them — even in the same file — is sent straight through as plain HTML.
<h1>My Page</h1>
<?php
echo "This part is PHP.";
?>
<p>This part is plain HTML again.</p>This is what makes PHP genuinely useful for building web pages: a single file can freely mix static HTML with dynamic PHP, switching between the two as often as needed. If a file contains only PHP (like a script you'll never mix with HTML), it's common practice to leave off the closing ?> tag entirely — it avoids an easy-to-miss bug where a stray blank line after it causes unexpected output.
Every PHP statement ends with a semicolon (;) — the same rule as JavaScript. Forgetting one is one of the most common beginner mistakes, and PHP will refuse to run the script until it's fixed.
<?php
echo "Line one";
echo "Line two"; // both statements need their own semicolon
?>PHP is a mix of case-sensitive and case-insensitive, and it catches people out: variable names are case-sensitive ($name and $Name are two different variables), but function and keyword names are not (echo, ECHO, and Echo all work identically). The safe habit is to always write everything in lowercase anyway, and treat variables as strictly case-sensitive.
PHP supports three comment styles, borrowed from other languages you may already recognize:
<?php
// single-line comment
# also a single-line comment
/* multi-line
comment */
?>// is by far the most common in practice. Comments are never sent to the browser — they exist purely for anyone reading the source code later, including future you.
Whitespace is for you, not PHP
Whitespace (spaces, tabs, blank lines) between statements doesn't matter to PHP the way it does in some other languages — it's there purely to help humans read the code. Consistent indentation is still worth keeping as a habit, even though PHP itself won't enforce it.
With the ground rules out of the way, the next lesson looks at how PHP actually stores data — starting with variables.