Sprintf in php what am I doing wrong
I am new to PHP and I am somewhat understanding it. Now I am working on something but I keep getting a error message saying Parse error: parse error, unexpected T_ECHO in C:\wamp\www\mymoney.php on line 11. Now I am looking at line 11 and I don't see anything i am doing wrong. So I was woundering if someone can help me understand what I might be doing wrong thanks.
<html>
<head>
<title>money $&开发者_如何学JAVAlt;/title>
</head>
<body>
<?php
$balance=55.75;
$newShirtCost=15.75;
$earns=20.00;
$buyscandybar=.55
echo "<p> Starting balance:" .sprintf("$%.2f",$balance)."</p>";
$balance= $balance -$newShirtCost;
echo "<p>Purchase: Clothing Store:".sprintf("$%.2f",$newShirtCost)."</p>";
$balance=$balance/2;
echo "<p>ATM Deposit:".sprintf("$%.2f",$earns)."</p>";
$balance=$balance-$buyscandybar;
echo "<p>Purchase: Gas Station:".sprintf("$%.2f",$buyscandybar)."</p>";
$balance=$balance
echo "<p>Ending Balance:".sprintf("$%.2f",$balance)."</p>";
?>
$buyscandybar=.55
Semicolon missed. When that error appears always check the line before too.
Also this makes no sense:
$balance=$balance
and it's without semicolon
Also you should separate your presentation by your logic
Use single-quotes strings or escape the $
with a \
. Single-quotes strings are preferred of course since escaping = ugly.
"Parse error" means exactly parse error. It usually locates before the place, where interpreter points you. You've missed ";" at line 10.
精彩评论