Variables
Read the echo function tutorial first.
We’ll start off with our basic PHP tags:
<?php
?>
And we’ll then add the variable:
<?php
$name
?>
The variable name can only contain letters, numbers and underscores, but it can’t start with a number.
This variable is now going to be equal to a string value which is contained in speech marks, just like the echo function.
<?php
$name = "Owen.";
?>
We’ll then create another variable called birthday, and this will be equal to my birthday:
<?php
$name = "Owen.";
$birthday = "5th of November.";
?>
Now, say, we made another variable called age, and it was equal to your age, it would be without speech marks, because it’s an integer, not a string:
<?php
$name = "Owen.";
$birthday = "5th of November.";
$age = 13;
?>
Now, we’ll add an echo, and we’ll echo the name variable:
<?php
$name = "Owen.";
$birthday = "5th of November.";
$age = 13;
echo "$name";
?>
Now, take a look at the file, and you’ll see that the name variable has been echoed. So, the variables are basically storing the information, and then you use the echo function for the information to actually be seen.
You can then add all of the different variables into one sentence, so you’re echoing the name, birthday and age variable:
<?php
$name = "Owen.";
$birthday = "5th of November.";
$age = 13;
echo "Hi, my name is $name, I'm $age and my birthday is on
the $birthday."
?>