1
다음 코드가 있습니다.preg_replace - 배열의 임의의 단어
<?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]을 (를) 대체하려고합니다. 아무것도 작동하지 않습니다!
도와 주시면 감사하겠습니다. =) 미리 감사드립니다!
고마워요 ^^ php $ user [ 'userID'] = '1'; $ 사용자 [ 'username'] = 'FooBar'; function repl ($ m) { \t 글로벌 $ 사용자; \t return $ user [$ m [1]]; } $ template = 'Hello {user:username}'; echo preg_replace_callback ('/ \ {사용자 \ : ([a-zA-Z0-9] +) \} /', 'repl', $ template); // 출력 : // 안녕하세요 FooBar – Patrick