php字符串算术表达式计算

 

$aa = "{1}*{2}-{3}";
$farr = array('/\{1\}/','/\{2\}/','/\{3\}/');
$tarr = array(3,4,10);
$str = preg_replace( $farr,$tarr,$aa);
echo $str;        //结果:3*4-10
echo eval('return '.$str.';');   //结果:2

来源:http://blog.51yip.com/php/1846.html

posted @ 2017-05-31 11:13  侠岚之弋痕夕  阅读(416)  评论(0编辑  收藏  举报
Where is the starting point, we don't have a choice, but the destination where we can pursue!