Learn PHP
PHP is a widely used server-side scripting language designed for building dynamic web pages and applications.
What is PHP?
PHP stands for "PHP: Hypertext Preprocessor", a recursive acronym that hints at its main job: preprocessing content on the server before it reaches the browser. It is an open-source language that runs on a web server, generating HTML (or JSON, images, files, and more) that the visitor's browser then displays. Because the code executes on the server, the person visiting your site never sees the PHP source itself, only the final output.
PHP has powered a huge share of the web for decades and remains the engine behind popular platforms such as WordPress, Drupal, and Laravel. It is beginner-friendly because you can mix it directly into HTML, yet it scales up to full-featured, object-oriented applications. Once you understand the basics here, you can move on to the PHP Install and PHP Syntax lessons.
What can PHP do?
- Generate dynamic page content that changes based on the user, time, or database data
- Create, read, write, and delete files on the server
- Collect and process data submitted through HTML forms
- Read and write to databases such as MySQL, PostgreSQL, and SQLite
- Manage sessions and cookies to remember users between requests
- Send and receive cookies, control user access, and encrypt sensitive data
A PHP file can contain plain text, HTML, and PHP code together. The PHP portions live inside special tags, and only that code is executed on the server. Everything outside the tags is sent to the browser unchanged.
Example
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello, world!";
?>
</body>
</html>In the example above, the browser receives the surrounding HTML as-is, but the line between the PHP tags is replaced by whatever the server produces. Here, echo prints the text "Hello, world!" into the page.
Why choose PHP?
Example
<?php
// PHP can output the current server date
echo "Today is " . date("Y-m-d");
?>Exercise: PHP Introduction
What is PHP primarily used for?
Frequently Asked Questions
- Is PHP still used in 2026?
- Yes. PHP runs a large share of the web, including WordPress, which alone powers a substantial fraction of all sites. Modern PHP 8 is considerably faster and better designed than its reputation suggests.
- Is PHP easy to learn?
- PHP is one of the more forgiving backend languages. It was built for the web, so handling forms, sessions and databases needs very little setup compared with most alternatives.
- What is PHP used for?
- Server-side web development: generating pages, handling form submissions, talking to databases and building APIs. It is the language behind WordPress, Drupal and Laravel.