Я пытаюсь внедрить короткие коды на своем веб-сайте, чтобы упростить публикацию. То, что я получил до сих пор, выглядит так:
$text = "[button]Hello[button] [input]holololo[input]";
$shortcodes = Array( 'button' => '<button>{content}</button>', 'input' => '<input type="text" value="{content}" />' );
$text = preg_replace_callback('(\[([a-z]+?)\](.+?)\[\\\1\])', function ($matches){
if ($shortcodes[$matches[1]]){
return str_replace('{content}', $matches[2], $shortcodes[$matches[1]]);
}else{
return $matches[0];
}
}, $text);
echo $text;
Я хочу, чтобы это повторялось: <button>Hello</button> <input type="text" value="holololo" />
Но вместо этого просто эхо: [кнопка]Привет[кнопка] [ввод]голололо[ввод]
Что я делаю не так?