Introduction to PHP

Introduction to PHP

PHP code is written inside <?php ... ?> tags, usually mixed into an .html-like file saved with a .php extension. When a browser requests that file, the server runs the PHP code first and sends only the resulting HTML to the browser the PHP code itself is never visible to the visitor.

Why this matters

  • ·Runs before the page reaches the browser, so logic stays hidden
  • ·Can mix directly with HTML in the same file

Common mistakes

  • ·Forgetting the closing ?> is usually fine, but forgetting <?php means PHP is never executed at all
  • ·Saving the file as .html instead of .php means the server won't run the PHP code
Your codePHP
Expected output
Hello World!

PHP runs on a server, not in the browser this shows the expected output instead of a live one.

Frequently asked questions

On the server, before the page reaches the browser.

Practice questions

Question 1

Write a PHP echo statement that prints your own name.

Your codePHP
Expected output

PHP runs on a server, not in the browser this shows the expected output instead of a live one.

Quick check

Just for this topic answer honestly, then check yourself.

1 / 2

Where does PHP code actually run?