PHP scripts are plain text files saved with the .php extension. PHP code is enclosed within opening <?php tags and closing ?> tags.
When the web server passes a file to the PHP parser, it evaluates code inside <?php ... ?> tags and leaves everything outside untouched as raw content.
<?php
// Standard PHP opening tag
$title = "Mastering PHP Syntax";
// Closing tag is required if file mixes HTML and PHP
?>
<h1><?= $title ?></h1>
<?php
// If a file contains ONLY PHP code, omit the closing tag!
flowchart LR
A["Raw HTML Text"] --> B["Parser Passes Through Directly"]
C["<?php Code Block ?>"] --> D["Parser Executes Logic"]
D --> E["Appends Result Output to Response"]
B --> E
;: Every individual PHP statement must end with a semicolon.if, else, echo, while) are case-insensitive.$name vs $Name) are strictly case-sensitive!?> at the end of pure PHP files prevents accidental trailing whitespace or header errors.<?php
declare(strict_types=1);
// Variable declarations (Case-Sensitive)
$userName = "Maksudur";
$username = "Guest"; // Different variable!
// Keyword case insensitivity (Convention is lowercase)
ECHO "Hello, " . $userName . "!
";
echo "Hello, " . $username . "!
";
// Semicolons terminate statements
$totalAmount = 150.00;
$discount = 15.00;
$finalPrice = $totalAmount - $discount;
echo "Final Payable Price: $" . number_format($finalPrice, 2);
echo, foreach, function).?> on Pure PHP Files: Avoid unexpected whitespace buffer output at the end of class or config files.declare(strict_types=1); at the very top of PHP files for scalar type safety.Write a PHP script that declares two variables $firstName and $lastName, concatenates them into $fullName, and prints $fullName using echo!
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.
You've completed this section! Take a quick 5-question quiz to check your understanding.