Reputation: 17
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Future Value</title>
</head>
<body>
<?php # Script 1.8 - futureValue.php.
// Set the variables:
$interest = .08;
$amount = 1000;
$years = 20;
// Calculate the value:
$value = $amount* pow( (1+$interest), $years);
// Format the total:
$value = number_format ($value, 2);
// Print the results:
echo "<p>The future value is <b>/$$value</b>.</p>";
?>
</body>
</html>
I tried pasting it here but the formatting got messed up.
Whenever I try to load the page it just says " The future value is /$$value. "; ?> " instead of displaying "The future value is $4660.96.".
I am totally lost at what I am doing wrong.
Upvotes: 1
Views: 66
Reputation: 1083
echo "<p>The future value is <b>$".$value."</b>.</p>";
$ is a special character so you need to escape it. Or you can always just concat your string and variable to avoid this problem.
Upvotes: 4