Andrew Sparrow
Andrew Sparrow

Reputation: 167

Regex Preg_replace

I'm trying to do a preg_replace to convert come bbcode. Basically, this

[QUOTE=ksiva]blahblah blah[/QUOTE]

Needs to look like this

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

I tried this preg replace, but it's not working. What am I doing wrong?

$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);

Upvotes: 0

Views: 161

Answers (1)

David
David

Reputation: 2423

Pop in this code, I think it's what you're looking for.

$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);

Upvotes: 1

Related Questions