Jump to content

[HARD] Multi quote regex (BBCode)


eevan79

Recommended Posts

This is too hard for me and I need some expert opinion if possible.

 

I want to implement multiquote feature with [ quote] [ /quote ] BB tags. I have 2 regex for BBCodes: [ quote = username] and just [ quote]

 

Here is BBCode tags:

    '/\[ quote\][\r\n]*(.+?)\[\/quote \][\r\n]*/si',
    '/\[ quote (.+?)\][\r\n]*(.+?)\[\/quote\][\r\n]*/si',

and replace:

 

 '<div class="quote">\\1</div>',
'<div class="quote"><div class="quoting">\\1: </div>\\2</div>',

 

When user click on Quote button (on posts page) I use this preg_replace:

$text = preg_replace(
                          '/<div class=\" quote \">(.+?): <\/div>(.+?)<\/div>/is', 
                          '[ quote ]\\2[/ quote ]', 
                          $text);

Note: this codes are without spaces (I must use space to show correct code)

 

To show quoted text in post form I use this:

$quoted_text = '[ quote=' . mysql_real_escape_string($_GET['u']) . ']' . $text['post_content'] . '[ /quote]';

(this is in textarea : <textarea>$quoted_text </textarea>)

 

Here is screenshot how it looks like.

First two quotes:

quotew.gif

 

 

and third quote have "bugs"

3rdquote.gif

 

Any ideas how to fix multiple quotes?

Link to comment
https://forums.phpfreaks.com/topic/210676-hard-multi-quote-regex-bbcode/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.