0

我正在尝试做一个 preg_replace 来转换来 bbcode。基本上,这

[QUOTE=ksiva]blahblah blah[/QUOTE]

需要看起来像这样

<div class=quote-msg"><div class="quote-author"><em>ksiva</em></div>blahblah blah</div>

我尝试了这个 preg 替换,但它不起作用。我究竟做错了什么?

$pattern = '#\[QUOTE=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/QUOTE\]#s';

$replace = '<div class="quote-msg"><div class="quote-author><em>$1</em></div>$2</div>';
$text = PREG_REPLACE($pattern, $replace, $text);
4

1 回答 1

1

弹出这段代码,我想这就是你要找的。

$pattern = '/\[QUOTE\=([^]]*)]([^\[]*)\[\/QUOTE]/';
$text = '[QUOTE=ksiva]blahblah blah[/QUOTE]';
$replace = "<div class=\"quote-msg\"><div class=\"quote-author\"><em>$1</em></div>$2</div>";
$text = PREG_REPLACE($pattern, $replace, $text);
于 2012-05-30T18:46:46.080 回答