LessonsPHP Basics → Lesson 1

Introduction to PHP

PHP
⏱ 10 min read 📖 Beginner Not completed

PHP is one of the most widely used programming languages on the web. It powers over 75% of all websites — including WordPress, Facebook (originally), and Wikipedia. In this lesson you'll learn what PHP is, how it works, and write your very first PHP script.

What is PHP?

PHP stands for PHP: Hypertext Preprocessor (a recursive acronym). It is a server-side scripting language — meaning the code runs on the web server, not in the user's browser.

Here's what happens when someone visits a PHP website:

How PHP Works
User's Browser  →  Request  →  Web Server (PHP runs here)
                                      ↓
                              PHP reads .php file
                                      ↓
                              PHP generates HTML
                                      ↓
User's Browser  ←  HTML Response  ←  Web Server

The user never sees your PHP code — they only see the final HTML output. This makes PHP great for dynamic websites, user authentication, database interactions, and more.

PHP vs HTML

HTML is static — it always shows the same content. PHP is dynamic — it can show different content based on conditions, database data, user input, and more.

HTML
<!-- Always shows the same thing -->
<p>Hello, John!</p>
PHP
<?php
// Shows different name based on who is logged in
$name = "John";
echo "Hello, {$name}!";
?>

Your First PHP Script

PHP code lives inside <?php and ?> tags. You can mix PHP with HTML in the same file. PHP files use the .php extension.

PHP — hello.php
<?php
echo "Hello, World!";
?>

// Output: Hello, World!

Mixing PHP with HTML

You can embed PHP inside HTML files to make them dynamic:

PHP + HTML
<!DOCTYPE html>
<html>
<body>

<?php
$name = "Suraj";
$day = date("l"); // Gets today's day name
?>

<h1>Hello, <?php echo $name; ?>!</h1>
<p>Today is <?php echo $day; ?>.</p>

</body>
</html>

// Output: Hello, Suraj!
//         Today is Friday.

PHP Comments

Comments are lines that PHP ignores — used to explain your code:

PHP
<?php

// This is a single-line comment

/* This is a
   multi-line comment */

echo "Comments are ignored by PHP";

?>

PHP is Case Sensitive (mostly)

PHP
<?php

// Variables ARE case sensitive
$color = "red";
echo $color;  // red
echo $Color;  // Error! $Color is not defined

// Keywords are NOT case sensitive
ECHO "hello";  // works
Echo "hello";  // works
echo "hello";  // works

?>
💡
Best practice: Always use lowercase for keywords like echo, if, while etc. It's the standard convention in PHP and makes your code more readable.

What Can PHP Do?

PHP is extremely versatile. Here's what you can build with it:

Use CaseExample
Dynamic websitesBlog, news site, e-commerce
User authenticationLogin, register, sessions
Database interactionMySQL, PostgreSQL
File handlingUpload, read, write files
REST APIsJSON endpoints for mobile apps
Email sendingContact forms, notifications
Web frameworksLaravel, Symfony, CodeIgniter
← Back to Lessons Next Lesson →
🧠

Test your knowledge!

Take the PHP Basics quiz to reinforce what you learned.

Take Quiz →