需要对字符串中匹配到的内容做一些复杂操作时,可以使用preg_replace_callback函数
$notice_content = preg_replace_callback('/(?<=\{)(\w+)(?=\})/',function ($matches) use ($params) {
return $params[$matches[0]];
},$detail['notice_content']);
其中function的参数matches是匹配到的字符,如果要在函数内部使用外部的变量,就用use传过去