Menu
Coddy logo textTech

Tags and Statements

Part of the Fundamentals section of Coddy's PHP journey — lesson 3 of 71.

Every PHP script must be properly structured to work correctly. PHP code doesn't run on its own - it needs special tags to tell the server where your PHP code begins and ends.

The opening tag <?php marks the start of your PHP code, while the closing tag ?> marks the end. Everything between these tags is treated as PHP code that the server will execute:

<?php
// Your PHP code goes here
?>

Within these tags, you write statements - individual instructions that tell PHP what to do. Each statement must end with a semicolon (;) to indicate where one instruction ends and the next begins. This semicolon is required and forgetting it will cause errors.

Here's a complete, valid PHP script structure:

<?php
echo "Welcome to PHP!";
?>

Notice how the echo statement ends with a semicolon. This proper structure - opening tag, statement with semicolon, closing tag - forms the foundation of every PHP program you'll write.

Cheat sheet

PHP code must be wrapped in opening and closing tags:

<?php
// Your PHP code goes here
?>

Each statement must end with a semicolon (;):

<?php
echo "Welcome to PHP!";
?>

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals