【发布时间】:2021-02-20 11:16:58
【问题描述】:
如何使用 std 对象进行动态替换? 在这种情况下,我不知道如何使用 $1 :( 见下文。
$lang->custom_name = "Me";
$lang->custom_email = "Me@me";
$html = "hello {{custom_name}} with {{custom_email}} ";
$html = preg_replace("/{{(custom_.*)}}/", $lang->{'$1'} , $html);
【问题讨论】:
-
什么是
$1? -
(custom_.*) stdClass 就像 $lang->custom_variablename
-
原始字符串长什么样子?
-
添加了更多代码来澄清
标签: php preg-replace preg-replace-callback