php · level 1 · unit 1 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
shows a message on the screen.
Every PHP program starts with <?php on its first line. This tells the computer that PHP code starts here. Without it, your code is shown as plain text instead of running.
echo shows something on the screen. Words go inside double quote marks, like "Hello, world!". A piece of text in quotes is called a . Picture the letters threaded on a string, like beads.
End each instruction with a semicolon, ;, like a full stop. The \n near the end means : it moves the screen on, ready for whatever comes next.
<?php
echo "Hello, world!\n"; The quotes and the \n are instructions for PHP, so they are not shown on the screen.
guess first
What will appear on the screen?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<?php
echo "My cat is called Pickles\n";
your turn
Your turn. Tell the computer what you love to eat.
Type your favourite food in place of the blank, keeping it inside the quotes. Then press run.
fix it
The computer shows the code instead. Fix it!
- Run it. The computer shows your code as plain text instead of following it. What is missing from the top?
- Every PHP program needs its opening tag on the first line, before any instructions.
- Add a new first line that says
<?php, then press run.
nailed it
you made the computer talk. :D
- Start every program with the
<?phpopening tag. echoshows a string, and;ends the instruction.\ninside the quotes starts a new line.
new words in your collection
- opening tag
- echo
- string
- new line
This lesson isn’t saved. A free account remembers every lesson you finish.