简体   繁体   中英

PHP - Echo is not displaying correctly

https://pastebin.com/pEg8ZARP

<!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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM