PHP - Echo无法正确显示

时间:2018-01-19 02:54:04

标签: php

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>

我试着在这里粘贴它,但格式化了。

每当我尝试加载页面时,它只是说“未来值是/ $$值。 “;?&gt;”而不是显示“未来价值为$ 4660.96。”。

我完全迷失了我的错误。

1 个答案:

答案 0 :(得分:3)

echo "<p>The future value is <b>$".$value."</b>.</p>";

$ 是一个特殊字符,因此您需要escape它。或者你可以随时concat使用你的字符串和变量来避免这个问题。