Re: PHP Newbie can't evaluate numerical string as number [message #175922 is a reply to message #175919] |
Mon, 07 November 2011 22:49 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma:
|
Senior Member |
|
|
Graham wrote:
> I'm a Perl veteran (well almost!) but a PHP newbie. […]
> <?php
> $formula = "!big_number - !small_number";
> ?>
> […]
> $big_number = 30000;
> $small_number = 3000;
> $formula = str_replace("!", "$", $formula);
> eval("\$formula = \"$formula\";");
You don't want a string, so don't make a string – remove the `\"'.
(I don't think Perl is so much different in that regard.)
> […]
> The above gives me...'formula = 30000 - 3000'
> when of course what I want is...'formula = 27000'
HTH
PointedEars
--
When all you know is jQuery, every problem looks $olvable.
|
|
|