我有以下代码。
<?php
$user['username'] = 'Bastian';
$template = 'Hello {user:username}';
$template = preg_replace('/\{user\:([a-zA-Z0-9]+)\}/', $user['\1'], $template);
echo $template;
// Output:
// Notice: Undefined index: \1 in C:\xampp\htdocs\test.php on line 5
// Hello
我想,你知道我会做什么(我希望你知道)。我尝试替换 $user['$1']、$user["$1"] 或 $user[$1],没有任何效果!
我希望你能帮助我=)提前谢谢你!