Jump to content

Archived

This topic is now archived and is closed to further replies.

master82

str_replace problem

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?

Share this post


Link to post
Share on other sites
[code]<?php

$calc="\$rate=".str_replace(array("L","E","F","I"), array('$l', '$e', '$f', '$I'),$field1).";";
eval($calc);

?>[/code]

Share this post


Link to post
Share on other sites
in that case: $field1 == ('' || null);

you need to look at where $field1 is declared and defined.

Share this post


Link to post
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]

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

×

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.