PHP is a server-side scripting language for building web pages. A .php file runs on the web server, prints HTML (for example with echo "<h1>Hello</h1>";), and the server sends that HTML to the visitor's browser. The browser never sees the PHP code, only its result.
Press Run: PHP builds the page below, and the Page tab shows it the way a browser would.
Switch to the Output tab and you see the plain HTML that PHP printed. That text is exactly what a browser would receive. Change a price or add an item and run it again.
What PHP is used for
PHP was made for the web, and that is still where most of it runs:
- Websites and CMSs. WordPress, Drupal and Joomla are written in PHP, and so is every site built on them.
- Web applications. Frameworks such as Laravel and Symfony are used for shops, dashboards, SaaS products and internal tools.
- APIs. A PHP script can print JSON instead of HTML, which is how many mobile apps and JavaScript frontends get their data.
- Command-line scripts. Cron jobs, data imports, report generators and deployment tools run with
php script.php, with no web server involved.
How a PHP request becomes HTML
When someone opens https://example.com/menu.php, this happens:
- The browser sends an HTTP request to the server.
- The web server (Apache, Nginx with PHP-FPM, or PHP's built-in server) sees the
.phpextension and hands the file to PHP. - PHP runs the file from top to bottom. Text outside
<?php ... ?>tags is copied to the output as it is; code inside the tags runs and canechomore text. - Whatever PHP printed becomes the response body, and the browser renders it.
- PHP forgets everything. The next request starts a fresh run of the script.
Step 5 is why PHP applications use sessions and databases: nothing in a variable survives between two requests. The form below shows the cycle. Run it, type a name into the form and press Send: the same script runs again, this time with $_POST filled in.
htmlspecialchars turns characters like < into <, so a name such as <b>Ada</b> is shown as text instead of becoming markup. Every value that comes from a visitor should be printed this way; the details are on the htmlspecialchars page.
PHP mixes with HTML
A PHP file can be pure code or an HTML page with PHP islands in it. Three tags do almost all the work:
| Tag | What it does |
|---|---|
<?php ... ?> | Runs the code inside |
<?= $value ?> | Short for <?php echo $value; ?> |
?> at the end of a file | Optional; leave it out in files that contain only PHP |
Set $hour to 9 and run it again to see the other greeting.
What PHP code looks like
Variables start with $, statements end with ;, and strings in double quotes can contain variables. Arrays work both as lists and as key/value maps.
The output is plain text here, because the script prints no HTML tags. That is the same code you would run from a terminal.
Modern PHP (PHP 8)
PHP 8.0 (2020) added match expressions, named arguments, union types, str_contains() and a JIT compiler; PHP 8.1 added enums and readonly properties. Code written for PHP 8.3 looks like this:
What PHP means
PHP stands for "PHP: Hypertext Preprocessor". The name is recursive: the first P stands for PHP itself. Rasmus Lerdorf released the first version in 1995 as "Personal Home Page Tools", a set of scripts for his own homepage, and the current name arrived with PHP 3 in 1998. "Hypertext preprocessor" describes the job well: PHP processes a file before the hypertext (HTML) is sent.
Common first mistake: opening a .php file in the browser
Double-clicking index.php opens it as a local file, and the browser either shows the raw PHP code or offers to download it. Nothing runs, because there is no PHP on the other end. A .php file has to be served by a web server that passes it to PHP. On your own computer the shortest way is PHP's built-in server:
php -S localhost:8000
Then open http://localhost:8000/index.php. The run PHP page covers this and running scripts from the terminal, and install PHP gets PHP onto your machine first.
Frequently Asked Questions
What does PHP stand for?
PHP stands for "PHP: Hypertext Preprocessor", a recursive acronym. The original 1995 name was "Personal Home Page Tools", from the scripts Rasmus Lerdorf wrote for his own website.
Is PHP a frontend or backend language?
Backend. PHP runs on the server, and the browser only receives the HTML (or JSON) that the script printed. The browser never sees the PHP code itself.
What is PHP mainly used for?
Building web pages and web applications on the server: content sites, shops, admin panels and APIs. WordPress, Drupal, Magento, Laravel and Symfony are all written in PHP. It also runs command-line scripts such as cron jobs and data imports.
Is PHP still used in 2026?
Yes. W3Techs reports PHP on roughly three quarters of the websites whose server-side language it can detect, largely because of WordPress. The language is actively developed: PHP 8.0 added match, named arguments and a JIT compiler, and PHP 8.1 added enums and readonly properties.
Is PHP easy to learn?
It is one of the easier first languages for web work: a file with <?php echo "Hello"; is already a working page, and every shared host runs it. The harder part is learning safe habits early, such as escaping output with htmlspecialchars and using prepared statements for SQL.