various aspects of your script very simple, consider the
<title><?php print "My First Script"; ?></title>
<h1><?php print "My First Script"; ?></h1>
with exactly the same data. What if you needed to change
that data? You would need to make at least 2 changes to the
above script. Now imagine if that script was an extra 200
lines long and you had half of those lines with the phrase
“My First Script” in them.
<?php $phrase = "My First Script"; ?>
<title><?php print $phrase; ?></title>
<h1><?php print $phrase; ?></h1>
named $phrase to the value of:
"My First Script"
where it’s referenced simply by using it’s name. If you try
changing the value of the variable, then re-run the script
in your browser you’ll see that the text in the web-page
will change to match.
$phrase = date("r");
and date, just as with the previous parts script where we
fed the output directly to the print statement. The above
example feeds the output of the date to the contents of the
variable, which can then be reused.