Please send questions to
st10@humboldt.edu .
<html>
<head>
<title> Playing with variables (part 1) </title>
</head>
<body>
<?php
// variable names start with a $, and no type declarations are
// needed
$welcome = 'Hello and welcome';
$num1 = 2;
$num2 = 4.35;
print $welcome;
print "<br>\n";
print $num1;
print "<br>\n";
print $num2;
print "<br>\n";
// what if I need to escape special characters?
// precede the needed character with a \
// for example, to have both single and double quotes in a string:
print "Here is a single quote ' and here is double quote \" ";
print "<br>\n";
print 'Here is a single quote \' and here is double quote " ';
print "<br>\n";
// like Perl, if you put a variable in a double-quoted string,
// the variable is replaced with its value;
// in a single-quoted string, it is not.
print "I am double-quoted: $welcome";
print "<br>\n";
print 'I am single-quoted: $welcome';
print "<br>\n";
// what if I'd like to have both? one way: backslash the $
print "The value of \$num1 is: $num1";
print "<br>\n";
// note that echo can be used as well as print....
echo "How are you?";
echo "<br>\n";
// and note that you can concatenate with a . not a +
echo $num1 + $num2;
// (and you can have a newline in a string literal in PHP...?)
echo "<br>
";
echo $num1 . $num2;
print $welcome . " and salutations! <br>\n";
// what happens if you try to use + with strings?
print $welcome + " and salutations! <br>\n";
?>
</body>
</html>