I have a string formula which I fetch from a file :
$text = "100*20";
I want to find a way to convert this formula into its result, for instance have the value 200. Is this possible using php?
I have a string formula which I fetch from a file :
$text = "100*20";
I want to find a way to convert this formula into its result, for instance have the value 200. Is this possible using php?
Use eval().
$expression = '100*20';
eval('$result = ('.$expression.')');
echo $result;
Make sure to investigate the security issues surrounding eval();
.
As the data is from a file it may be ok, but if it is user input - don't.