master82 Posted September 4, 2006 Share Posted September 4, 2006 In my table i have the field 'field1' and an example of its data is below:[code]((F*0.8)/1)+(L/4)[/code]Its simply a small calculation, which uses the following code:[code]$calc="\$rate=".str_replace(array("L","E","F","I"), array($l, $e, $f, $I),$field1).";";eval($calc);[/code]When the code is run I get the following error:[quote]Parse error: parse error, unexpected ';' in LOCATION\PAGE.php(60) : eval()'d code on line 1[/quote]Any idea what it is i'm doing wrong?Also Im using $rate later on in the page - will there be a problem with this? Quote Link to comment https://forums.phpfreaks.com/topic/19660-str_replace-problem/ Share on other sites More sharing options...
Jenk Posted September 4, 2006 Share Posted September 4, 2006 [code]<?php$calc="\$rate=".str_replace(array("L","E","F","I"), array('$l', '$e', '$f', '$I'),$field1).";";eval($calc);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19660-str_replace-problem/#findComment-85673 Share on other sites More sharing options...
master82 Posted September 4, 2006 Author Share Posted September 4, 2006 I added the ' ' around the 4 variables but still got the same error message Quote Link to comment https://forums.phpfreaks.com/topic/19660-str_replace-problem/#findComment-85675 Share on other sites More sharing options...
Jenk Posted September 4, 2006 Share Posted September 4, 2006 change the eval to echo, what do you get? Quote Link to comment https://forums.phpfreaks.com/topic/19660-str_replace-problem/#findComment-85676 Share on other sites More sharing options...
master82 Posted September 4, 2006 Author Share Posted September 4, 2006 $rate=; Quote Link to comment https://forums.phpfreaks.com/topic/19660-str_replace-problem/#findComment-85678 Share on other sites More sharing options...
Jenk Posted September 4, 2006 Share Posted September 4, 2006 in that case: $field1 == ('' || null);you need to look at where $field1 is declared and defined. Quote Link to comment https://forums.phpfreaks.com/topic/19660-str_replace-problem/#findComment-85679 Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 Use[code=php:0]$calc = "\$rate = str_replace(array(\"L\",\"E\",\"F\",\"I\"), array(\$l, \$e, \$f, \$I), \$field1);";[/code]If you are using eval.However i see no use for eval here. Just use:[code=php:0]$rate = str_replace(array("L","E","F","I"), array($l, $e, $f, $I), $field1);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19660-str_replace-problem/#findComment-85680 Share on other sites More sharing options...
master82 Posted September 4, 2006 Author Share Posted September 4, 2006 Sorry - just realised I mispelt the field - hence no value!Thanks for your time guys! Quote Link to comment https://forums.phpfreaks.com/topic/19660-str_replace-problem/#findComment-85681 Share on other sites More sharing options...
master82 Posted September 4, 2006 Author Share Posted September 4, 2006 Its always the simple things... lol Quote Link to comment https://forums.phpfreaks.com/topic/19660-str_replace-problem/#findComment-85682 Share on other sites More sharing options...
Jenk Posted September 4, 2006 Share Posted September 4, 2006 [quote author=wildteen88 link=topic=106833.msg427692#msg427692 date=1157372216]Use[code=php:0]$calc = "\$rate = str_replace(array(\"L\",\"E\",\"F\",\"I\"), array(\$l, \$e, \$f, \$I), \$field1);";[/code]If you are using eval.However i see no use for eval here. Just use:[code=php:0]$rate = str_replace(array("L","E","F","I"), array($l, $e, $f, $I), $field1);[/code][/quote]it appears that $field1 contains an equation, the OP is trying to replace Keywords with values, and then execute the equation. eval() will be needed if the OP wants that equation to execute in PHP :) Quote Link to comment https://forums.phpfreaks.com/topic/19660-str_replace-problem/#findComment-85702 Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 Oh i see. Didnt realise that. Thanx for the heqads up. Quote Link to comment https://forums.phpfreaks.com/topic/19660-str_replace-problem/#findComment-85705 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.