我试图用 preg_replace 制作一个 bbCode 系统,它运行一个函数,但由于某种原因,输出仅为 1 美元,即使我添加了“e”修饰符。
任何想法如何解决这个问题?
源代码:
function bbcode($value){
$pattern[0] = "/\{register\}(.*?)\{\/register\}/sie";
$replace[0] = register('$1'); //"<pre>$1</pre>";
$bbcoded = preg_replace($pattern, $replace, $value);
return $bbcoded;
}
function register($var) {
echo $var;
}
$content = '
{b}text{/b}
{register}
"register" = "setting",
"name" = "title",
"order" = "1"
{/register}
some text
{register}
"register" = "setting",
"name" = "url",
"order" = "3"
{/register}
some more {b}t{/b}e{b}xt{/b}
{register}
"register" = "setting",
"name" = "description",
"order" = "2"
{/register}
text text
';
$content = bbcode($content);
看看它在行动:http ://sandbox.onlinephpfunctions.com/code/08459c4fec1919e6089d3849e154ba7a83900fd7