Keyword to BBCODE

npole2000

New member
I need a script (or a method) to convert certain keywords in a BBCODE type text.
In example:

Keywords to find: TEST1-, TEST2-
BBCODE: [MYBBCODE]

This post:

TEXT TEST1-123 TEXT
TEXT TEST2-123 TEXT

Will change to:
TEXT [MYBBCODE]TEST1-123[/MYBBCODE] TEXT
TEXT [MYBBCODE]TEST2-123[/MYBBCODE] TEXT
---

I do accomplish the above in vB, with the following PHP (but I don't know how to convert it in a XF addon):

Code:
$advanced_bbcode = array(
     '/(?<=\s|^|\()TEST1-[0-9]+/',
     '/(?<=\s|^|\()TEST2-[0-9]+/'
);
if ($this->post['pagetext']) {
   $this->post['pagetext'] = preg_replace($advanced_bbcode, '[MYBBCODE]$0[/MYBBCODE]', $this->post['pagetext']);
}
 

npole2000

New member
Ah.. sorry forgot to mention an important thing. I need this to be done while posting, not for the contents already in the database.
So when submitting a post with the keywords, they must be converted in a BBCODE. That is what I'm actually doing with vB using the plugin/script above.
 
Top