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
| Version | Key Feature | Status |
|---|---|---|
| PHP 7.x | 2ร speed, scalar type declarations | EOL |
| PHP 8.0 | JIT, Union Types, Match expression | EOL |
| PHP 8.1 | Enums, Fibers, readonly properties | Security fixes |
| PHP 8.2 | readonly classes, DNF types | Active |
| PHP 8.3 | Typed 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.