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
// PHP code that runs on the server
$name = "John";
echo "<h1>Hello, {$name}!</h1>";
?>
▶ Try it Yourself

What the browser actually receives after the code runs:

HTML
<h1>Hello, John!</h1>

Output:

TEXT
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

TEXT
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
Facebook 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

PHP
<!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>
▶ Try it Yourself

Output:

TEXT
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).

💡 Tip: PHP is perfect for anyone with front-end skills who wants to learn back-end development. You know HTML and CSS? Then the barrier to entry is practically zero—you embed PHP right into the HTML you already know.


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
ℹ️ Note: PHP 6 was skipped. At the time, the plan was to add full Unicode support, but after years of development the approach proved misguided and the project was abandoned in 2010. The version jumped straight from 5 to 7—a famous event in programming history.

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:

TEXT
JS (Front-end)                    PHP (Back-end)
  ↓                                    ↓
Click "Login" button  ──POST request──→  Validate username & password
  ↓                                    ↓
Show login result    ←──JSON response──  Return user info

❓ FAQ

Q Is PHP outdated?
A Absolutely not. PHP 8.x offers massive performance gains (3x faster than PHP 5), and modern frameworks like Laravel and Symfony rival the best practices of any language. 78% of the web runs on PHP, and PHP developers are among the most in-demand globally (especially in Brazil and the Middle East).
Q What do I need to know before learning PHP?
A HTML is enough. You should know how to use a browser and create folders. You don't need to learn C or Python first.
Q What's the relationship between PHP and WordPress?
A WordPress is a content management system written in PHP. After finishing this tutorial's PHP fundamentals, you'll understand how WordPress works under the hood and even be able to write your own WordPress plugins and themes.
Q What's the relationship between PHP and Laravel?
A Laravel is a web framework written in PHP. PHP is the language; Laravel is the toolkit—like a screwdriver set for building web apps. This tutorial teaches PHP itself. Lesson 36 will give you a taste of Laravel.

📖 Summary

📝 Exercises

  1. 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?
  2. Search for "PHP 8 features," learn about the latest features, and pick the one you think is coolest. Write it down.
  3. Search for companies that use PHP today (domestic and international) to get a sense of the PHP job market.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏