FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » PHP Newbie can't evaluate numerical string as number
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
PHP Newbie can't evaluate numerical string as number [message #175919] Mon, 07 November 2011 16:25 Go to previous message
Graham is currently offline  Graham
Messages: 4
Registered: November 2011
Karma:
Junior Member
I'm a Perl veteran (well almost!) but a PHP newbie. I've got a simple
subtraction formula in 'vars.php' as follows:

<?php
$formula = "!big_number - !small_number";
?>

I then include it in 'test.php' along with a few variables, do a bit of
string replacement, run eval on it, then print it

<?PHP
include 'vars.php';
$big_number = 30000;
$small_number = 3000;
$formula = str_replace("!", "$", $formula);
eval("\$formula = \"$formula\";");
//$formula = intval($formula);
//settype($formula, "integer");
print ("formula = $formula\n");
?>

The above gives me...'formula = 30000 - 3000'
when of course what I want is...'formula = 27000'

A few of the many things I've tried are commented out. Please put me out of
my misery someone!
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: shiping cart program
Next Topic: he discount UGG boots are best known for its "Classic" sheepskin boots.
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 07 07:25:35 GMT 2024

Total time taken to generate the page: 0.06338 seconds