我正在尝试使用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);
答案 0 :(得分: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);