开发者

handling a string as PHP [duplicate]

This question already has an answer here: Closed 10 years ago.

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜