PHP (Hypertext Preprocessor) is an open-source, server-side scripting language built for web development. When a browser requests a PHP page, the web server runs the PHP script first and sends only plain HTML or JSON back to the user.
Because PHP executes on your backend server, visitors never see your source code, database passwords, or internal business rules.
flowchart LR
A["Browser Request"] --> B["Web Server (Nginx / Apache)"]
B --> C["PHP 8 Runtime"]
C --> D["MySQL Database"]
D --> C
C --> E["HTML or JSON Response"]
E --> A
Modern PHP 8 powers small business sites, custom REST APIs, and large platforms like WordPress and Laravel. It runs on Linux, macOS, and Windows servers without changing your application code.
You can mix PHP logic with HTML templates by wrapping server instructions inside <?php ... ?> tags. Always escape dynamic strings with htmlspecialchars() so user input cannot inject unsafe scripts into the page.
<?php
declare(strict_types=1);
$serverTime = date('Y-m-d H:i:s');
$userRole = 'Editor';
$activeModules = ['User Accounts', 'Invoice Generator', 'Email Queue'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PHP Server Status</title>
</head>
<body>
<h2>PHP Server Information</h2>
<p>Server Time: <strong><?= htmlspecialchars($serverTime) ?></strong></p>
<p>Current Role: <span><?= htmlspecialchars($userRole) ?></span></p>
<h3>Enabled Modules</h3>
<ul>
<?php foreach ($activeModules as $module): ?>
<li><?= htmlspecialchars($module) ?></li>
<?php endforeach; ?>
</ul>
</body>
</html>
.php files directly from your file explorer: Browsers cannot run PHP locally via file://. Always serve files through a web server or php -S localhost:8000.$_GET or database strings without htmlspecialchars() creates Cross-Site Scripting (XSS) vulnerabilities.No. Browsers only understand HTML, CSS, and JavaScript. The web server executes PHP first and returns the rendered output to the browser.
Yes. PHP 8 offers typed properties, JIT compilation, and mature frameworks like Laravel and Symfony that power millions of modern production APIs and websites.
Save PHP scripts with the .php extension so the web server knows to pass the file to the PHP interpreter instead of serving it as plain text.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.