0

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);
2
  • What might the [QUOTE=name] part look like? Could it be just [QUOTE] or does it have to have a name? What will the names look like? Commented May 30, 2012 at 18:33
  • This works fine - the only thing is that you're not putting a double quote after <div class="quote-author - fix that and you should be good to go. Commented May 30, 2012 at 18:41

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.