I got stucked in to achieve 45 from"0.45*100"
both are in string. How can we get result as 45 from above. i have used eval() function also but no result. Please help.
Asked
Active
Viewed 391 times
0

Can Vural
- 2,222
- 1
- 28
- 43

vinay kumar reddy
- 127
- 7
-
1WARNING: This is asking for an injection attack. Assuming the `0.45*100` is coming from the user, I would validate it's in the form you expect, extract all the parameters, and then multiply explicitly rather than calling eval. – charles-allen Sep 18 '17 at 06:18
2 Answers
2
Try eval()
which return your operation
$test = "0.45*100";
$value=eval("return ($test);");
echo $value;

B. Desai
- 16,414
- 5
- 26
- 47
1
Please check below code using eval()
Working Demo: https://eval.in/863366
$expression = '0.45*100';
eval( '$result = (' . $expression . ');' );
echo $result;
Outtput:
45

Jigar Shah
- 6,143
- 2
- 28
- 41