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
https://forums.phpfreaks.com/topic/62407-removing-the-bbcode_id-from-bbcode-tags/
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.