Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #3710
| Message-ID | <5823112.UsPfZmn7uG@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2011-11-07 23:49 +0100 |
| Subject | Re: PHP Newbie can't evaluate numerical string as number |
| Newsgroups | comp.lang.php |
| References | <A8OdnXgegKYUmyXTnZ2dnUVZ7ridnZ2d@bt.com> |
| Followup-To | comp.lang.php |
Followups directed to: comp.lang.php
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.
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
PHP Newbie can't evaluate numerical string as number "Graham" <graham.stow@stowassocs.co.uk> - 2011-11-07 16:25 +0000
Re: PHP Newbie can't evaluate numerical string as number The Natural Philosopher <tnp@invalid.invalid> - 2011-11-07 16:56 +0000
Re: PHP Newbie can't evaluate numerical string as number Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-07 17:52 +0000
Re: PHP Newbie can't evaluate numerical string as number "Graham" <graham.stow@stowassocs.co.uk> - 2011-11-08 08:41 +0000
Re: PHP Newbie can't evaluate numerical string as number Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-11-08 09:56 +0100
Re: PHP Newbie can't evaluate numerical string as number "Graham" <graham.stow@stowassocs.co.uk> - 2011-11-08 09:35 +0000
Re: PHP Newbie can't evaluate numerical string as number Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-08 09:57 +0000
Re: PHP Newbie can't evaluate numerical string as number Tim Streater <timstreater@greenbee.net> - 2011-11-08 10:08 +0000
Re: PHP Newbie can't evaluate numerical string as number Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-08 17:49 +0000
Re: PHP Newbie can't evaluate numerical string as number "Graham" <graham.stow@stowassocs.co.uk> - 2011-11-08 10:27 +0000
Re: PHP Newbie can't evaluate numerical string as number Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-07 23:49 +0100
Re: PHP Newbie can't evaluate numerical string as number Jonathan Stein <jstein@image.dk> - 2011-11-08 11:19 +0100
csiph-web