How to strip bbcode from text

Discussion forum for Extension Writers regarding Extension Development.
Tarantino
Registered User
Posts: 874
Joined: Sat Feb 18, 2012 1:51 pm

Re: How to strip bbcode from text

Post by Tarantino »

JoshyPHP wrote: Tue Jun 06, 2017 5:39 pm Here's what I ran:

Code: Select all

$text = '<r><B><s>[b]</s>bold<e>[/b]</e></B> :lol: http://google.com</r>';
strip_bbcode($text);
die($text);
Here's what I got:

Code: Select all

 bold  :lol: http://google.com
Does it work differently for you?
Hi there, I saw a problem today and saw here on your example the same problem. strip_bbcode adds a space when removing bbcode.
So if we've: Some text with bold. Text
It will become: Some text with bold . Text

And we don't want that extra space :/
User avatar
JoshyPHP
Code Contributor
Posts: 1288
Joined: Mon Jul 11, 2011 12:28 am

Re: How to strip bbcode from text

Post by JoshyPHP »

There's nothing in phpBB that does that specifically. For messages posted on 3.2, you can remove most formatting with s9e\TextFormatter\Utils::removeFormatting($xml). That's what strip_bbcode() uses via clean_formatting().
I wrote the library that handles markup in phpBB 3.2+.
Post Reply

Return to “Extension Writers Discussion”