handling a string as PHP [duplicate]
Possible Duplicate:
PHP: Calculate 开发者_C百科a math function f(x) in a string
I have a little problem. I have a string, such that,
$a = '(2+3+4)';
How can I handle $a such that the output, echo $a should be 9 instead of just giving (2+3+4).
If your code is indeed $a = (2+3+4), then echo will output 9.
It sounds like you have it a string. You could eval() that string to get the 9.
Have a look at php's Eval function
$string = "(2+3+4)";
eval('$a = '.$string);
echo $a;
加载中,请稍侯......
精彩评论