很容易解释我想要实现的目标,但对我来说(PHP的新手),很难真正实现它。基本上我想要的是使BBCodes尽可能容易和短。而不是像
这样的数组$filter=array(
'[b]'=>'<b>',
'[/b]'=>'</b>',
'[i]'=>'<i>',
'[/i]'=>'</i>');
我想要这个阵列:
$filter=array('b','i');
然后,我无法达到的部分,就是它检查该数组中的字符串以便在它们周围放置括号(而另一件我无法弄清楚的是,能够检查{括号中的{1}}然后用/
替换这些括号。因此,<>
将成为[b]
,<b>
将成为[/b]
。
编辑:解决方案
</b>
答案 0 :(得分:0)
$filter = array('b','i');
$newfilter = array();
foreach ($filter as $tag) {
$newfilter["[$tag]"] = "<$tag>";
$newfilter["[/$tag]"] = "</$tag>";
}
现在您可以使用$newfilter
。