【发布时间】:2014-02-20 23:01:23
【问题描述】:
我正在尝试在我的网站上实施短代码以简化发布。到目前为止我得到的看起来像这样:
$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" />
但它只是回显:[button]Hello[button] [input]holololo[input]
我做错了什么?
【问题讨论】: