Re: $string . "text" not working properly
| From: | Ignacio Vazquez-Abrams | Date: | Mon, 13 Nov 2000 16:56:17 +0000 |
| Subject: | Re: $string . "text" not working properly | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24977@lists.php.net to get a copy of this message | ||
On Mon, 13 Nov 2000, Brian T. Allen wrote:
> 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
>
"-" and "." have the same precedence. But parentheses around your
subtraction.
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>