PHP Explained: The Language That Quietly Powers Most of the Web
Introduction
PHP powers an enormous share of the live web — WordPress alone runs a large fraction of all websites, and it is written in PHP. Yet PHP rarely gets the attention newer languages do. That is a shame, because PHP is the clearest way to understand how the web actually works: a browser asks for a page, a server runs code, and the result is sent back as HTML.
The request cycle, in one example
A PHP file mixes HTML and code. When a visitor requests the page, the server runs the code first and sends only the result — the visitor never sees the PHP itself.
<?php
$name = "Sara";
$hour = 10;
?>
<!DOCTYPE html>
<html>
<body>
<h1>Hello, <?php echo $name; ?>!</h1>
<p>
<?php
if ($hour < 12) {
echo "Good morning.";
} else {
echo "Good afternoon.";
}
?>
</p>
</body>
</html>
Three ideas are already visible. Variables start with $, which makes them easy to spot. <?php ... ?> marks code inside an otherwise normal HTML page. And echo outputs text into the page the visitor receives. The browser sees only the finished HTML — no PHP, no logic, just the result.
Forms: where PHP earns its keep
The moment a website needs a contact form, a login, or a search box, it needs server-side code. PHP reads submitted form data directly:
<?php
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$message = $_POST["message"] ?? "";
echo "You wrote: " . htmlspecialchars($message);
}
?>
<form method="post">
<input type="text" name="message">
<button type="submit">Send</button>
</form>
$_POST holds the submitted data, ?? "" supplies a safe default if nothing was sent, and htmlspecialchars escapes the input so a visitor cannot inject HTML into your page. That last step is not optional — it is the difference between a working form and a security hole.
Modern PHP is not the PHP of old jokes
PHP's reputation for messiness comes from the early 2000s. Modern PHP — version 8 and later — has strict types, named arguments, match expressions, and frameworks like Laravel that bring clean structure, routing, and database tools. WordPress, Laravel, and Symfony all run on it today, and PHP developers remain in steady demand for maintaining and building the web's biggest platforms.
Takeaway
A browser asks, the server runs PHP, and only finished HTML comes back. Learn the request cycle, form handling with safe output, and you understand not just PHP, but the server-side web itself.
Comments
Post a Comment