php正则提取字符串 然后将结果格式化为变量

正文开始

<p>类似js里的eval</p><p><br /></p><p><pre>//正则替换字符串 function pregReplace($strSource="", $reg="",  $vals=[]) {     $n= preg_match_all($reg,  $strSource, $maches);     if($n > 0) {         //$maches Array([0] => Array([0] => {a}[1] => {b})  [1] => Array([0] => a [1] => b))         foreach($maches[1] as $math){             if(isset($vals[$math])){                 $strSource = str_replace('{'.$math.'}', $vals[$math], $strSource);             } else {                 $strSource = str_replace('{'.$math.'}', '', $strSource);             }         }     }     return $strSource; } </pre></p><p><pre>$str = "thiis : {a}, {b}"; $sonV = [ 'a' => 666666, 'b' => 999, ]; $reg = "/{([^}]*)}/"; print_r(pregReplace($str, $reg, $sonV));</pre> <br /></p>

正文结束

PHP接口(interface)和抽象类(abstract) thinkPHP5配置nginx环境无法打开(require(): open_basedir restriction in effect. File(/mnt/hgfs/root/tp5/thinkphp/start.php) is not within the allowed path(s)