Chapter practice task
Task: Build a small “about me” page that changes its greeting by time of day
- Create
about.phpand print your name, job title and city from variables. - Join strings to build a full sentence like “Hi, I’m Anmol, a web designer from India.”
- Use
date('G')and if/elseif/else to show “Good morning”, “Good afternoon” or “Good evening”. - Show a “Currently available for projects” line only when a
$availablevariable 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.