Jump to content

Removing the bbcode_id from bbcode tags


HaLo2FrEeEk

Recommended Posts

Ok, phpbb, at least, puts a unique ID number into each bbcode tag a user posts, for example, if I were to post bold text and look at the raw code in the database, it would look like this:

 

[b:9f0e836e4c]bold text[/b:9f0e836e4c]

 

Now, it's simple enough to remove those numbers using this regex:

 

[b:[^\]]+]

 

What's really got me stumped, though, is how to do this when the bbcode has attributes, such as size and a quote:

 

Test quote

 

Would end up being:

 

Test quote[/quote:9f0e836e4c]

 

And:

 

Test size

 

turns into:

 

Test size[/size:9f0e836e4c]

 

What I need to know is how I can use one regex to handle both the opening, AND the closing tags for these, and still keeping the attribute value (so saving it to a backreference).

 

EDIT: I got the size one working, I need help with quote though.

 

I used this one for quote, but it only did the opening tag, and not the closing one:

 

preg_replace("[quote:[^\]]+(=[.]*)]", "quote$1", $text);

 

The thought was that if the attribute was there (i.e., an opening tag) then it would save the backreference and replace it, if it's not there, it will ignore it.  It doesn't work though, and it only replaces the opening tag, forcing me to have another regex to handle the closing tag.

 

What can I do to fix this?

 

Thank you.

 

EDIT:

 

Regex:

 

]+(=[.]*)]

 

Turns:

 

Test quote[/quote:9f0e836e4c]

 

Into:

 

[quote="HaLo2FrEeEk"]Test quote[/quote:9f0e836e4c]

 

And regex:

 

]+(=[.]*)?]

 

Turns:

 

Test quote[/quote:9f0e836e4c]

 

Into:

 

[quote]Test quote[/quote]

 

I'm stumped.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.