Jump to content

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/19660-str_replace-problem/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/19660-str_replace-problem/#findComment-85680
Share on other sites

[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 :)
Link to comment
https://forums.phpfreaks.com/topic/19660-str_replace-problem/#findComment-85702
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.