PHP code structure defines how PHP scripts are written and embedded within files. PHP runs on the server and must be enclosed inside PHP tags so the server can interpret and execute it correctly.
.php extensionPHP scripts start with an opening tag and end with a closing tag. Everything inside these tags is processed as PHP code.
// Basic PHP opening and closing tags
<?php
echo "PHP code goes here";
?>
A PHP script can be embedded inside an HTML document to dynamically generate content.
// PHP embedded inside an HTML page
<!DOCTYPE html>
<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<h1>Welcome</h1>
<?php
echo "This is a PHP block!";
?>
</body>
</html>
<?php ... ?> — Standard PHP tag<?= ... ?> — Short echo tag
// Using standard and short echo PHP tags
<?php
echo "Hello, World!";
?>
<?= "Hello again!"; ?>
The server processes the PHP code and sends only the output (HTML/text) to the browser. The PHP code itself is never visible to the user.
Think of PHP as a backstage worker. It prepares the final HTML on the server before the browser ever sees it.
Type something below to see how PHP's echo command converts your code into what the user actually sees.
Browser Output (What the user sees):
structure.phphttp://localhost/structure.php