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
起点在哪,或许选择不了。重要的是,你追求的终点在哪!
$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