Topic: [extension release] Search Strip BBCode

This extension strips BBCode from search results, displayed "as post".

Due to a strange bug (take a look at source), it doesn't remove [url=http://example.net]-like BBCode. Feedback is desired.

Download here: http://www.punres.org/files.php?pid=497

Sourcecode: (Changed [/ code] and [/ quote ])

include_once PUN_ROOT.'include/parser.php';
$pun_page['message'] = preparse_bbcode($pun_page['message'], $parse_errors);
$pun_page['message'] = str_replace(
        array('[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[url]', '[/url]', '[email]', '[/email]', '[quote]', '[ /quote ]', '[img]', '[/img]', '[/color]', '[ code ]', '[ /code ]'),
        array('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''),
        $pun_page['message']
);

//why doesn't this work? feedback desired
//$pun_page['message'] = preg_replace( '#\[url=([^\[]*?)\]#e', '$1 ', $pun_page['message']);

$pun_page['message'] = preg_replace( '#\[email=([^\[]*?)\]#', '$1 ', $pun_page['message']);
$pun_page['message'] = preg_replace( '#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})]#s', '', $pun_page['message']);
$pun_page['message'] = preg_replace('#\[quote=("|"|\'|)(.*)\\1\]#seU', 'str_replace(array(\'[\', \'\\"\'), array(\'[\', \'"\'), \'$2\')." ".$lang_common[\'wrote\'] ', $pun_page['message']);

2

Re: [extension release] Search Strip BBCode

You would need something akin to: '[url.+?]' to remove the [url=]type tag. (My regex/pcre is a tad rusty, btw). big_smile

Re: [extension release] Search Strip BBCode

Well... I took the original RegExp from the PunBB source code, and it doesn't work wink I'd be happy if a PunBB dev would take a look at it smile

4

Re: [extension release] Search Strip BBCode

Or you could always brush up on your regular expressions. smile http://pcre.org/pcre.txt