Jump to content

Constants


Lee

Recommended Posts

i am learning from a book, & it has not illustrated how constants should be written.
I wrote this code..

[code]<html>
<head><title>Constants</title></head>
<body>
<?php /* this is a script using a simple constant to make a calculation*/
define("TRADE_DISCOUNT", 0.75);
$Amount= 20.00;
$Discount= 2.50;
$Trade= $Amount * TRADE_DISCOUNT;

echo "A cheap guitar costs {$Amount}. You can get a discount of {$Discount}.<br />
    When you buy at trade price though, you get it at {$Trade}.

?>
</body>
</html>[/code]

But I get this error..
[quote]
Parse error: parse error, unexpected $end in C:\wamp\www\constants.php on line 15[/quote]

I don't understand about line 15, thats just the closing html tag, but obviously I'm doing something wrong.
Can anyone enlighten me please?

Thanks  :)
Link to comment
Share on other sites

Ok I'm into another pickle.
This code..
[code]<?php /* this is a script using a simple constant to make a calculation*/
define("TRADE_DISCOUNT", 0.75);
$Amount= 20.00;
$Discount= 2.50;
$Trade= $Amount * TRADE_DISCOUNT;

echo "A cheap guitar costs {$Amount}. You can get a discount of {$Discount}.<br />
    When you buy at trade price though, you get it at {$Trade}. <p>";

echo "We can buy it for £",TRADE_DISCOUNT;
?>

<?php
/* this is the line & file constants (line tells you hat line it is on, File tells you the path to the file*/

echo __LINE__;

echo __FILE__;
?>[/code]
..produces this in the browser

[quote]A cheap guitar costs 20. You can get a discount of 2.5.
When you buy at trade price though, you get it at 15.

We can buy it for £0.75 20 [/quote]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.