TExcelTAD
Home › PHP › PHP Intro

PHP Introduction

PHP is a server-side scripting language built for the web. A PHP program runs on a web server, produces some text (usually HTML), and sends that text to the visitor's browser. The browser never sees the PHP code itself — only the result.

The name originally stood for "Personal Home Page"; today it is the recursive acronym PHP: Hypertext Preprocessor. Rasmus Lerdorf released the first version in 1995, and the language has grown up a lot since then. Modern PHP (version 8 and later) has a fast JIT-capable engine, type declarations, enums, match expressions, readonly properties and much more.

What can PHP do?

  • Generate dynamic web pages (the same template shows a different shopping cart for every user)
  • Read and process HTML forms
  • Store and load data from databases such as MySQL, PostgreSQL and SQLite
  • Create, read and write files on the server
  • Send and receive cookies, and remember users with sessions
  • Build JSON APIs for mobile apps and JavaScript front ends
  • Run command-line scripts and scheduled jobs

Large platforms such as WordPress, Wikipedia (MediaWiki), Drupal and the Laravel and Symfony frameworks are all written in PHP.

Why learn PHP?

Feature What it means for you
Made for the web Request data, cookies, headers and HTML output are built in
Runs almost everywhere Nearly every web host supports PHP out of the box
Gentle start A useful script can be three lines long
Mature ecosystem Composer packages, Laravel, Symfony, WordPress
Modern language Types, classes, enums, closures and attributes in PHP 8

How a PHP page works

  1. The browser asks the server for /hello.php.
  2. The web server hands the file to the PHP engine.
  3. PHP runs the code from top to bottom and collects everything it prints.
  4. The server sends that output back to the browser as the response.

Because the work happens on the server, the visitor cannot read your database password or business logic — they only get the generated page.

Note: The playgrounds on ExcelTAD run real PHP 8.4 compiled to WebAssembly directly in your browser. The first run downloads the PHP engine (a few megabytes), so it may take a moment. After that, runs are quick. Everything a script prints appears below the editor.

Your first PHP program

A PHP file starts with the opening tag <?php. Everything after it is PHP code. The echo statement sends text to the output. Press ▶ Run:

php · try it yourself
<?php
echo "Hello, World!\n";
Hello, World!

The \n at the end of the string is a newline character, so the next output starts on a fresh line. In a browser page you would normally output HTML tags like <br> or <p> instead, but in these playgrounds plain text lines are easier to read.

Tip: Every playground is editable. Change the message and run it again — you cannot break anything.

PHP runs line by line

Statements run in order, and each one ends with a semicolon ;:

php · try it yourself
<?php
echo "PHP runs on the server.\n";
echo "It sends the result to the browser.\n";
echo "The visitor only sees the output.\n";
PHP runs on the server.
It sends the result to the browser.
The visitor only sees the output.

A taste of dynamic output

The real power of PHP is that the output can change. Variables start with a $ sign, and double-quoted strings can include them directly:

php · try it yourself
<?php
$product = "coffee mug";
$price = 8.5;
$quantity = 3;
$total = $price * $quantity;

echo "You ordered $quantity x $product.\n";
echo "Total to pay: $total EUR\n";
You ordered 3 x coffee mug.
Total to pay: 25.5 EUR

On a real website, $quantity might come from a form the visitor submitted and $price from a database. You will learn both later in this course.

What you will learn

This course follows a practical path:

  1. PHP basics — syntax, variables, strings, numbers, arrays, loops and functions
  2. Forms and the web — handling form data, validation, files, dates, JSON and exceptions
  3. Object-oriented PHP — classes, interfaces, traits, enums and readonly properties
  4. Databases — PDO with SQLite, prepared statements and CRUD
  5. Practice — exercises and a small project

Test yourself

Where does PHP code run?

  1. In the visitor's browser
  2. On the web server
  3. Only inside a database
  4. In the operating system kernel

Which tag starts a block of PHP code?

  1. <php>
  2. <?php
  3. <script php>
  4. #!php

What does echo do?

  1. Reads input from the user
  2. Declares a variable
  3. Sends text to the output
  4. Stops the script