$subject = '你好啊,我是{abc},我最爱看的电视是《{xyz}》'; $data = [ 'abc' => '小明', 'xyz' => '还珠格格', ]; preg_match_all('|{.*}|U', $subject , $matches); $result = $subject; foreach ($matches[0] as $slot) { $key = substr($slot, 1, -1); $result = str_replace($slot, $data[$key] ?? '', $result); } echo $subject, "\n"; echo $result, "\n";