Search found 3 matches

by dzim
Sat Aug 06, 2005 3:20 am
Forum: PHP - Code
Topic: [Solved]Calculating expression in string
Replies: 4
Views: 389

Assuming you get the string at runtime, so there is no way to get it parsed regularly... But be careful where you get the string from, because there will be a day that people send you 'exec("rm -rf /")' $string = '$price/$duration*$fix'; eval('<?php $cost=' . $string . ';?>'); As it says ...
by dzim
Sat Aug 06, 2005 3:16 am
Forum: PHP - Code
Topic: [Solved]Calculating expression in string
Replies: 4
Views: 389

don't put it in quotes It's not my decision. :) I'm getting the string from mySQL. Keep in mind the order of operations will be in effect. Mulitply and divide first, then subtraction and add, then lastly, left to right so if you want ($price/$duration)*fix or $price/($duration*fix) make sure you sp...
by dzim
Fri Aug 05, 2005 6:43 pm
Forum: PHP - Code
Topic: [Solved]Calculating expression in string
Replies: 4
Views: 389

[Solved]Calculating expression in string

Hi.

I have a string:

$cost = '$price/$duration*$fix';

and I need to calculate the cost.
If I use eval() function, it just replaces variables with numbers,
but it does nothing with operators '/' and '*'.
Is there any other way to do this, except parsing it "manualy"?

Thanks.