Thuta Learning
BasicProgrammingbeginner

Syntax

Relax. We'll talk through this in plain words — no textbook voice.

A PHP script <?php starts with ?> and can end with it. In pure PHP files, you can actually leave out the closing tag. Every statement needs to end with a semicolon ;. Forgetting the semicolon is usually the first fight beginners have with PHP.

php
<?php
// Single-line comment
echo "<h1>This heading comes from PHP</h1>";

/*
 Multi-line comment
 Useful when explaining bigger blocks
*/
echo "<p>This paragraph also comes from PHP.</p>";
?>
You should see
The browser shows a heading and a paragraph.

Easy traps

  • Forgetting to close a quote you opened, or forgetting the semicolon, will cause a syntax error.
Syntax | Thuta Learning