Theory
Introduction to PHP
PHP 8.3.8
Getting Started

Introduction to PHP

Topic 1 of 13
What is PHP?
PHP stands for PHP: Hypertext Preprocessor. It's a server-side scripting language powering ~77% of all websites โ€” including WordPress, Facebook (originally), and Wikipedia.

PHP is embedded directly in HTML, runs on a web server (Apache/Nginx/Caddy), and outputs HTML, JSON, or XML. It connects to databases, handles sessions, files, and much more.

Basic PHP File

PHPindex.php
<?php
  echo "Hello, World!";
?>

<!-- Mix PHP with HTML -->
<h1><?php echo "Dynamic Title"; ?></h1>

// Shorthand echo (great for templates)
<?= "Quick echo" ?>

// Pure PHP file โ€” closing ?> is optional (prevents whitespace bugs)

How PHP Works

โ‘  Browser requests page.php โ†’ โ‘ก Server runs PHP engine โ†’ โ‘ข PHP outputs HTML โ†’ โ‘ฃ Browser receives pure HTML. The PHP source is never visible to the user.

PHP Versions

VersionKey FeatureStatus
PHP 7.x2ร— speed, scalar type declarationsEOL
PHP 8.0JIT, Union Types, Match expressionEOL
PHP 8.1Enums, Fibers, readonly propertiesSecurity fixes
PHP 8.2readonly classes, DNF typesActive
PHP 8.3Typed class constants, json_validate()Current
๐Ÿ’ก Tip
Always omit the closing ?> in pure PHP files โ€” it prevents accidental whitespace being sent before headers, which breaks header() calls and sessions.