PHP is one of the most widely used server-side scripting languages in the world. It powers millions of websites — from small personal blogs to massive platforms like WordPress, Facebook (in its early days), and Wikipedia. If you want to build dynamic, data-driven websites, PHP is one of the best places to start.
PHP stands for Hypertext Preprocessor (it was originally called "Personal Home Page"). It is an open-source, server-side scripting language designed specifically for web development.
PHP handles the "behind the scenes" work that makes websites feel alive and personalised. Here are some things PHP does every day on the web:
Understanding the flow of a PHP request helps everything else make sense. Here is what happens when someone visits a PHP-powered page:
.php file and passes it to the PHP engine.Every PHP script begins with <?php and ends with ?>. Let us write the classic first program — displaying a simple message on screen:
<?php
echo "Hello, World!";
?>
When the server runs this file, it produces the following output in the browser:
Hello, World!
echo statement is how PHP sends text (or HTML) to the browser. You will use it constantly throughout your PHP journey.
One of PHP's most powerful features is that you can mix PHP code directly inside an HTML file. The PHP parts are processed by the server, and the final result is a clean HTML page:
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Welcome to My Website</h1>
<?php
$name = "Alice";
echo "<p>Hello, " . $name . "! Welcome back.</p>";
?>
</body>
</html>
The browser receives this as pure HTML:
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Welcome to My Website</h1>
<p>Hello, Alice! Welcome back.</p>
</body>
</html>
$name variable and echo statement are completely invisible to the visitor. All they see is the resulting HTML paragraph.
$, for example: $username.; — forgetting it is one of the most common beginner mistakes.// for single-line or /* ... */ for multi-line.?> at the end of a file that contains only PHP code. In fact, leaving it out is considered best practice because it prevents accidental whitespace from being sent before headers.
php -S) and a http://localhost/... URL.
<?php. Anything outside the tags — even one leading blank line — is sent to the browser as output. Once you start using session_start() or header(), this causes a confusing "headers already sent" error.
echo with return. echo immediately prints output to the browser; return sends a value back to whatever called a function. Mixing them up is a common source of "why is nothing showing up" bugs.
A second example showing PHP doing something a static HTML file can't — computing the current year automatically so the footer never goes stale:
<?php
$year = date("Y");
echo "<p>© $year RedoHub. All rights reserved.</p>";
?>
The browser only ever sees the finished HTML, like © 2026 RedoHub. All rights reserved. — the date() call and the logic behind it are invisible to visitors.
Q: Can I open a .php file by double-clicking it?
A: No — it needs to be requested through a web server (even a local one like php -S localhost:8000) so the PHP engine actually runs the code before it reaches the browser.
Q: Do I need to close the PHP tag ?> at the end of a file?
A: If the file contains only PHP code, it's best practice to omit the closing tag — this avoids accidental trailing whitespace that can trigger "headers already sent" errors.
Q: What's the difference between echo and print?
A: They behave almost identically — print returns a value of 1 and can only take one argument, while echo can take multiple, comma-separated arguments and is very slightly faster. See the official PHP manual for the exact differences.