PHP code lives inside tags so the server knows what to execute versus what to send as plain HTML. The modern standard is <?php ... ?>; short tags <?= echo shorthand are common in templates.
Standard opening tag
<?php
echo "Hello, world!\n";
?>
Every statement ends with a semicolon. Omitting it causes a parse error on the next line.
Mixing PHP and HTML
<?php $name = 'Ada'; ?>
<p>Hello, <?= htmlspecialchars($name) ?></p>
In real templates, always escape output with htmlspecialchars (or a template engine) to prevent XSS.
CLI vs web SAPI
The same syntax runs in the browser context (via a web server) and on the command line (php script.php). This playground uses the CLI-style runner—no HTML wrapper required unless you echo it.
Important interview questions and answers
- Q: Why use full
<?phptags?
A: Portability—short tags may be disabled inphp.ini; full tags work everywhere. - Q: What is
<?=?
A: Short echo tag, equivalent to<?php echo ... ?>when enabled.
Self-check
- What punctuation ends a PHP statement?
- Why escape user data before echoing into HTML?
Tip: Always use full <?php tags in portable code—short tags may be disabled in production php.ini.