PHP: Introduction to PHP
If you already know HTML and CSS and can build beautiful static web pages, PHP is the next step to make your sites come alive. HTML is the walls and floors of a house; PHP is the wiring and plumbing that makes everything work.
1. What Is PHP?
PHP is a server-side scripting language designed specifically for creating dynamic web pages and web applications.
The name is a recursive acronym: "PHP: Hypertext Preprocessor." In plain English: PHP code runs on the server, and once it finishes running, the server sends pure HTML back to the browser. When you "view page source" in the browser, you'll never see PHP code—only the HTML it generated.
▶ Example: PHP Runs on the Server
<?php
// PHP code that runs on the server
$name = "John";
echo "<h1>Hello, {$name}!</h1>";
?>
What the browser actually receives after the code runs:
<h1>Hello, John!</h1>
Output:
Browser renders: a large heading "Hello, John!" — PHP executed on the server and sent this pure HTML to the browser.
(1) How PHP Processes a Request
You type a URL in the browser
↓
The request reaches the web server
↓
The PHP engine executes your PHP code
↓
PHP queries the database, processes logic, generates HTML
↓
Pure HTML is sent back to the browser
↓
You see a dynamic web page
All PHP processing happens on the server. Your computer doesn't need any PHP software installed.
2. Why Learn PHP?
PHP is the most widely used server-side language in the world. Roughly 78% of all websites run PHP, including these sites you visit every day:
| Site | Type | Scale |
|---|---|---|
| WordPress | Blogs / Business Sites | Powers 43% of all websites |
| Social Network | Originally built with PHP (later developed HHVM) | |
| Wikipedia | Encyclopedia | One of the top 5 websites globally |
| Magento / WooCommerce | E-commerce | Millions of online stores |
| Laravel Apps | Web Applications | The most-starred PHP framework on GitHub |
(1) PHP's Core Strengths
Edit and run instantly — no compilation wait. Change code → refresh browser → see results immediately. Unlike Java or C#, which require a compile step before you can run, PHP offers a refreshingly fast development experience.
Natively embedded in HTML. You can write PHP code directly inside your HTML files:
▶ Example: PHP Embedded in HTML to Output the Date
<!DOCTYPE html>
<html>
<body>
<h1>Welcome — <?php echo date("F j, Y"); ?></h1>
<p>Current time: <?php echo date("H:i:s"); ?></p>
</body>
</html>
Output:
Output displayed
Built-in web capabilities. PHP was designed for the web from day one. Handling forms, reading/writing cookies, managing sessions, uploading files—these are tasks that require frameworks in other languages but come standard with PHP.
Massive ecosystem. PHP has 5,000+ built-in functions, thousands of third-party libraries (installed via Composer), and the world's largest open-source CMS ecosystem (WordPress, Drupal, Joomla).
3. What Can PHP Do?
| Use Case | Description | You'll Learn |
|---|---|---|
| Dynamic Web Pages | Generate different content based on user, time, or data | Phases 1–3 |
| Form Handling | Collect user input, validate, and store it | Phase 3 |
| User Systems | Registration, login, permission management | Phases 3–4 |
| Database-Driven Sites | Articles, products, data displays | Phase 5 |
| File Uploads & Management | Image uploads, file storage | Phase 3 |
| RESTful APIs | Provide data interfaces for front-end / mobile apps | Later Laravel Tutorial |
| Command-Line Scripts | Scheduled tasks, data processing | After mastering the basics |
By the end of this 36-lesson tutorial, you'll be able to build a complete blog system on your own—with user registration and login, article publishing and management, categories, search, comments, and more.
4. PHP Version History
| Version | Year | Milestone |
|---|---|---|
| PHP 1.0 | 1995 | Released by Rasmus Lerdorf, originally called "Personal Home Page Tools" |
| PHP 3.0 | 1998 | Kernel rewrite, renamed "PHP: Hypertext Preprocessor" |
| PHP 4.0 | 2000 | Zend Engine — huge performance boost |
| PHP 5.0 | 2004 | Full object-oriented support, PDO database abstraction layer |
| PHP 7.0 | 2015 | 2x performance, type declarations, PHP 6 skipped |
| PHP 8.0 | 2020 | JIT compiler, match expression, named arguments, union types |
| PHP 8.1 | 2021 | Enums, Fibers (coroutines), readonly properties |
| PHP 8.2+ | 2022+ | Readonly classes, standalone types null/false/true |
This tutorial is based on PHP 8.x standards. Everything you learn here is modern PHP.
5. PHP vs. JavaScript
Beginners often confuse these two because both can be embedded in HTML. But they run in completely different places:
| PHP | JavaScript | |
|---|---|---|
| Where it runs | Server | Browser |
| Can users see the source code? | ❌ No | ✅ Yes (View Source) |
| Can it access a database? | ✅ Directly | ❌ Needs a back-end API |
| Can it read/write server files? | ✅ Yes | ❌ No |
| Can it manipulate the page DOM? | ❌ No (done after generating HTML) | ✅ That's its job |
| What's it best for? | Back-end logic, data storage | Front-end interaction, animation |
A typical collaboration pattern:
JS (Front-end) PHP (Back-end)
↓ ↓
Click "Login" button ──POST request──→ Validate username & password
↓ ↓
Show login result ←──JSON response── Return user info
❓ FAQ
📖 Summary
- PHP is a server-side scripting language — code runs on the server and returns HTML to the browser
- ~78% of all websites use PHP (WordPress, Wikipedia, and many more)
- PHP's core strengths: instant edit-and-run, native HTML embedding, built-in web capabilities, 5,000+ functions
- PHP 8.x is modern PHP — powerful performance, rich feature set
- PHP and JavaScript run in completely different places: one on the server, one in the browser
- By the end of this tutorial, you'll be able to build a full blog system on your own
📝 Exercises
- Open a website you visit often and think: which parts of the site are "dynamic" (change based on user or time)? Which parts are static?
- Search for "PHP 8 features," learn about the latest features, and pick the one you think is coolest. Write it down.
- Search for companies that use PHP today (domestic and international) to get a sense of the PHP job market.