Faouzi Nikolaic Faouzi Nikolaic - 2 months ago 7
PHP Question

Convert a string formula into its result 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;