Skip to content
Chapter 01 of 05 · 3 lessons · ~26 min

PHP Basics

Run your first PHP script, store data in variables and make decisions with if and else.

YOUR PROGRESS0%
/ Lessons in this chapter
01
Your First PHP Script (Hello World) How PHP works on a server, how to run it on your own computer, and how to print your first line of output. Coming soon
02
PHP Variables and Strings How to store values in variables, the main data types, and how to build and change text with strings. Coming soon
03
PHP If Else Statements How to make decisions in PHP with if, elseif, else, comparison operators and the match expression. Coming soon

Chapter practice task

Task: Build a small “about me” page that changes its greeting by time of day

  1. Create about.php and print your name, job title and city from variables.
  2. Join strings to build a full sentence like “Hi, I’m Anmol, a web designer from India.”
  3. Use date('G') and if/elseif/else to show “Good morning”, “Good afternoon” or “Good evening”.
  4. Show a “Currently available for projects” line only when a $available variable is true.

By the end of this chapter

  • You can run PHP files on your own computer
  • You know how PHP mixes with HTML on the same page
  • You can store text and numbers in variables and join strings together
  • You can show different content with if, elseif and else

Quick answers for this chapter

Why does my browser show PHP code instead of running it?

You opened the file directly (the address starts with file://). PHP needs a server. Open it through http://localhost instead.

Do PHP files need the .php extension?

Yes. The server only runs PHP inside files that end in .php.

Is PHP case-sensitive?

Variable names are ($name and $Name are different). Function names and keywords like echo and if are not, but write them in lowercase anyway.