RE: [PHP] $string . "text" not working properly
| From: | Paul Williams | Date: | Mon, 13 Nov 2000 16:55:09 +0000 |
| Subject: | RE: [PHP] $string . "text" not working properly | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24979@lists.php.net to get a copy of this message | ||
Hi Brian,
Try
$MESSAGE .= $IMAGE . "Only $" . ($AMOUNT - $USED) . " available.<br>\n";
it seems the text append (.) has higher priority over subtract (-) so it
seems to be doing
($IMAGE . "Only $" . $AMOUNT) - $USED
Putting parenthesis around the arithmetic fixes the problem.
Cheers
Paul
-----Original Message-----
From: php-general-return-24975-pwilliams=firstream.com@lists.php.net
[mailto:php-general-return-24975-pwilliams=firstream.com@lists.php.net]O
n Behalf Of Brian T. Allen
Sent: 13 November 2000 16:49
To: Php
Subject: [PHP] $string . "text" not working properly
Hi *,
Consider the following code, which I think should work:
<?
$IMAGE = "<img src=\"/images/error.gif\">";
$MESSAGE = "Message:<br>\n";
$AMOUNT = "10";
$USED = "6";
$MESSAGE .= $IMAGE . "Only $" . $AMOUNT - $USED . " available.<br>\n";
echo $MESSAGE;
?>
This should output:
Message:<br>
<img src=\"/images/error.gif\">Only $4 available.<br>
But instead it outputs:
Message:<br>
-6 available.<br>
Notice that it drops the $IMAGE and "Only $", not to mention calculating
the math incorrectly (actually, it drops $AMOUNT resulting in an
accurate but unwanted "0 - 6" calculation.
I have long suspected problems with the $VAR = $START . " hello world "
. $END; syntax, but this is the first easily reproducible instance of
it.
I have used the following as a workaround, but it is of course
unacceptable in the long-run:
$MESSAGE .= $IMAGE;
$MESSAGE .= "Only $";
$MESSAGE .= $AMOUNT - $USED;
$MESSAGE .= " available.<br>\n";
Any thoughts or suggestions?
Brian