I'm trying to implement short codes on my website to make publishing easier. What i got so far look like this:
$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;
What i want this to echo is: <button>Hello</button> <input type="text" value="holololo" />
But instead it just echo's out: [button]Hello[button] [input]holololo[input]
What am I doing wrong?