Skip to content
Learn Netverks

Lesson

Step 6/36 17% through track

opening-tags

Opening tags and basic output

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~2 min
Level
beginner

This lesson

This lesson teaches Opening tags and basic output: the syntax, APIs, and habits you need before advancing in PHP.

Teams ship Opening tags and basic output on every PHP codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Opening tags and basic output in contexts like: LAMP/LEMP stacks, Laravel apps, WordPress themes/plugins, and shared hosting.

Write PHP in the editor and click Run on server—the dev runner executes your script and returns stdout/stderr (set LEARNING_RUNNER_ENABLED=true locally).

When you can explain the previous lesson's ideas without copying starter code.

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

  1. Q: Why use full <?php tags?
    A: Portability—short tags may be disabled in php.ini; full tags work everywhere.
  2. Q: What is <?=?
    A: Short echo tag, equivalent to <?php echo ... ?> when enabled.

Self-check

  1. What punctuation ends a PHP statement?
  2. 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.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Short open tag risk?
  • When omit closing tag?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump