Introduction to PHP

Uploaded : 4 months ago Updated : 4 months ago beginner

Take The Quiz

Take The Quiz

What is PHP?

PHP is a server-side language that powers a huge share of the web (WordPress, Laravel…). It runs on the server, builds HTML, and sends it to the browser.

How PHP fits in

Unlike JavaScript in the browser, PHP runs before the page reaches the user. It can read databases, handle forms and generate dynamic HTML.

Your first PHP script

<?php
  echo "Hello, world!";
?>

Files end in .php

PHP code lives between <?php and ?>. Anything outside those tags is sent to the browser as-is.

Variables

PHP variables start with a $. No type declaration needed.

<?php
$name = "Ada";
$age = 30;
echo "Name: $name, Age: $age";

PHP needs a server

Open a .php file directly and you just see the code. Run it with a local server (e.g. php -S localhost:8000) or Laragon/XAMPP.

Echo and string interpolation

<?php
$user = "Sam";
echo "Welcome, $user!";   // double quotes interpolate
echo 'Welcome, $user!';   // single quotes do NOT

Frequently asked questions

Is PHP still relevant?
Yes — it runs much of the web and powers modern frameworks like Laravel and Symfony.
Frontend or backend?
Backend: PHP runs on the server. Pair it with HTML/CSS/JS on the front.
Which version?
Use PHP 8.x — it is fast and has modern features.

Ready for more?

Next, learn arrays, conditions, loops and functions — the core of PHP logic.

Continue to PHP Fundamentals

Comments