The values in variables can be interpolated if you put them into double-quoted strings.
<html> <head> <title>PHP</title> <meta Name="Author" Content="Hann So"> </head> <body> <p> <?php $welcome = "Welcome to PHP class"; echo "$welcome. We have a lot of materials to learn"; ?> </p> </body> </html> |
If you want to add a word to the output of the variable, enclose the variable that you're interpolating in curly braces { and }.
<html>
<head>
<title>Interpolating Variables in Strings</title>
<meta Name="Author" Content="Hann So">
</head>
<body>
<p>
<?php
$meat = "meat";
echo "Do you like to eat spaghetty with $meatballs?<br /><br />";
// enclose the variable with curly braces
echo "Do you like to eat spaghetty with {$meat}balls?<br /><br />";
?>
</p>
</body>
</html>
|