There is no ready decision for PHP 5.5.x.
Here is how it was made for FluxBB:
Old
function do_bbcode($text, $is_signature = false)
{
global $lang_common, $pun_user, $pun_config, $re_list;
if (strpos($text, '[quote') !== false)
{
$text = preg_replace('%\[quote\]\s*%', '</p><div class="quotebox"><blockquote><div><p>', $text);
$text = preg_replace('%\[quote=("|&\#039;|"|\'|)(.*?)\\1\]%se', '"</p><div class=\"quotebox\"><cite>".str_replace(array(\'[\', \'\\"\'), array(\'[\', \'"\'), \'$2\')." ".$lang_common[\'wrote\']."</cite><blockquote><div><p>"', $text);
$text = preg_replace('%\s*\[\/quote\]%S', '</p></div></blockquote></div><p>', $text);
}
if (!$is_signature)
{
$pattern[] = $re_list;
$replace[] = 'handle_list_tag(\'$2\', \'$1\')';
}
$pattern[] = '%\[b\](.*?)\[/b\]%ms';
$pattern[] = '%\[i\](.*?)\[/i\]%ms';
$pattern[] = '%\[u\](.*?)\[/u\]%ms';
$pattern[] = '%\[s\](.*?)\[/s\]%ms';
$pattern[] = '%\[del\](.*?)\[/del\]%ms';
$pattern[] = '%\[ins\](.*?)\[/ins\]%ms';
$pattern[] = '%\[em\](.*?)\[/em\]%ms';
$pattern[] = '%\[colou?r=([a-zA-Z]{3,20}|\#[0-9a-fA-F]{6}|\#[0-9a-fA-F]{3})](.*?)\[/colou?r\]%ms';
$pattern[] = '%\[h\](.*?)\[/h\]%ms';
$replace[] = '<strong>$1</strong>';
$replace[] = '<em>$1</em>';
$replace[] = '<span class="bbu">$1</span>';
$replace[] = '<span class="bbs">$1</span>';
$replace[] = '<del>$1</del>';
$replace[] = '<ins>$1</ins>';
$replace[] = '<em>$1</em>';
$replace[] = '<span style="color: $1">$2</span>';
$replace[] = '</p><h5>$1</h5><p>';
if (($is_signature && $pun_config['p_sig_img_tag'] == '1') || (!$is_signature && $pun_config['p_message_img_tag'] == '1'))
{
$pattern[] = '%\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]%e';
$pattern[] = '%\[img=([^\[]*?)\]((ht|f)tps?://)([^\s<"]*?)\[/img\]%e';
if ($is_signature)
{
$replace[] = 'handle_img_tag(\'$1$3\', true)';
$replace[] = 'handle_img_tag(\'$2$4\', true, \'$1\')';
}
else
{
$replace[] = 'handle_img_tag(\'$1$3\', false)';
$replace[] = 'handle_img_tag(\'$2$4\', false, \'$1\')';
}
}
$pattern[] = '%\[url\]([^\[]*?)\[/url\]%e';
$pattern[] = '%\[url=([^\[]+?)\](.*?)\[/url\]%e';
$pattern[] = '%\[email\]([^\[]*?)\[/email\]%';
$pattern[] = '%\[email=([^\[]+?)\](.*?)\[/email\]%';
$pattern[] = '%\[topic\]([1-9]\d*)\[/topic\]%e';
$pattern[] = '%\[topic=([1-9]\d*)\](.*?)\[/topic\]%e';
$pattern[] = '%\[post\]([1-9]\d*)\[/post\]%e';
$pattern[] = '%\[post=([1-9]\d*)\](.*?)\[/post\]%e';
$pattern[] = '%\[forum\]([1-9]\d*)\[/forum\]%e';
$pattern[] = '%\[forum=([1-9]\d*)\](.*?)\[/forum\]%e';
$pattern[] = '%\[user\]([1-9]\d*)\[/user\]%e';
$pattern[] = '%\[user=([1-9]\d*)\](.*?)\[/user\]%e';
$replace[] = 'handle_url_tag(\'$1\')';
$replace[] = 'handle_url_tag(\'$1\', \'$2\')';
$replace[] = '<a href="mailto:$1">$1</a>';
$replace[] = '<a href="mailto:$1">$2</a>';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?id=$1\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?id=$1\', \'$2\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?pid=$1#p$1\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?pid=$1#p$1\', \'$2\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewforum.php?id=$1\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewforum.php?id=$1\', \'$2\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/profile.php?id=$1\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/profile.php?id=$1\', \'$2\')';
// This thing takes a while! :)
$text = preg_replace($pattern, $replace, $text);
return $text;
}
New
function do_bbcode($text, $is_signature = false)
{
global $lang_common, $pun_user, $pun_config, $re_list;
if (strpos($text, '[quote') !== false)
{
$text = preg_replace('%\[quote\]\s*%', '</p><div class="quotebox"><blockquote><div><p>', $text);
$text = preg_replace_callback('%\[quote=("|&\#039;|"|\'|)(.*?)\\1\]%s', create_function('$matches', 'global $lang_common; return "</p><div class=\"quotebox\"><cite>".str_replace(array(\'[\', \'\\"\'), array(\'[\', \'"\'), $matches[2])." ".$lang_common[\'wrote\']."</cite><blockquote><div><p>";'), $text);
$text = preg_replace('%\s*\[\/quote\]%S', '</p></div></blockquote></div><p>', $text);
}
if (!$is_signature)
{
$pattern_callback[] = $re_list;
$replace_callback[] = 'handle_list_tag($matches[2], $matches[1])';
}
$pattern[] = '%\[b\](.*?)\[/b\]%ms';
$pattern[] = '%\[i\](.*?)\[/i\]%ms';
$pattern[] = '%\[u\](.*?)\[/u\]%ms';
$pattern[] = '%\[s\](.*?)\[/s\]%ms';
$pattern[] = '%\[del\](.*?)\[/del\]%ms';
$pattern[] = '%\[ins\](.*?)\[/ins\]%ms';
$pattern[] = '%\[em\](.*?)\[/em\]%ms';
$pattern[] = '%\[colou?r=([a-zA-Z]{3,20}|\#[0-9a-fA-F]{6}|\#[0-9a-fA-F]{3})](.*?)\[/colou?r\]%ms';
$pattern[] = '%\[h\](.*?)\[/h\]%ms';
$replace[] = '<strong>$1</strong>';
$replace[] = '<em>$1</em>';
$replace[] = '<span class="bbu">$1</span>';
$replace[] = '<span class="bbs">$1</span>';
$replace[] = '<del>$1</del>';
$replace[] = '<ins>$1</ins>';
$replace[] = '<em>$1</em>';
$replace[] = '<span style="color: $1">$2</span>';
$replace[] = '</p><h5>$1</h5><p>';
if (($is_signature && $pun_config['p_sig_img_tag'] == '1') || (!$is_signature && $pun_config['p_message_img_tag'] == '1'))
{
$pattern_callback[] = '%\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]%';
$pattern_callback[] = '%\[img=([^\[]*?)\]((ht|f)tps?://)([^\s<"]*?)\[/img\]%';
if ($is_signature)
{
$replace_callback[] = 'handle_img_tag($matches[1].$matches[3], true)';
$replace_callback[] = 'handle_img_tag($matches[2].$matches[4], true, $matches[1])';
}
else
{
$replace_callback[] = 'handle_img_tag($matches[1].$matches[3], false)';
$replace_callback[] = 'handle_img_tag($matches[2].$matches[4], false, $matches[1])';
}
}
$pattern_callback[] = '%\[url\]([^\[]*?)\[/url\]%';
$pattern_callback[] = '%\[url=([^\[]+?)\](.*?)\[/url\]%';
$pattern[] = '%\[email\]([^\[]*?)\[/email\]%';
$pattern[] = '%\[email=([^\[]+?)\](.*?)\[/email\]%';
$pattern_callback[] = '%\[topic\]([1-9]\d*)\[/topic\]%';
$pattern_callback[] = '%\[topic=([1-9]\d*)\](.*?)\[/topic\]%';
$pattern_callback[] = '%\[post\]([1-9]\d*)\[/post\]%';
$pattern_callback[] = '%\[post=([1-9]\d*)\](.*?)\[/post\]%';
$pattern_callback[] = '%\[forum\]([1-9]\d*)\[/forum\]%';
$pattern_callback[] = '%\[forum=([1-9]\d*)\](.*?)\[/forum\]%';
$pattern_callback[] = '%\[user\]([1-9]\d*)\[/user\]%';
$pattern_callback[] = '%\[user=([1-9]\d*)\](.*?)\[/user\]%';
$replace_callback[] = 'handle_url_tag($matches[1])';
$replace_callback[] = 'handle_url_tag($matches[1], $matches[2])';
$replace[] = '<a href="mailto:$1">$1</a>';
$replace[] = '<a href="mailto:$1">$2</a>';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?id=\'.$matches[1])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?id=\'.$matches[1], $matches[2])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?pid=\'.$matches[1].\'#p\'.$matches[1])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?pid=\'.$matches[1].\'#p\'.$matches[1], $matches[2])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/viewforum.php?id=\'.$matches[1])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/viewforum.php?id=\'.$matches[1], $matches[2])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/profile.php?id=\'.$matches[1])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/profile.php?id=\'.$matches[1], $matches[2])';
// This thing takes a while! :)
$text = preg_replace($pattern, $replace, $text);
$count = count($pattern_callback);
for($i = 0 ; $i < $count ; $i++)
{
$text = preg_replace_callback($pattern_callback[$i], create_function('$matches', 'return '.$replace_callback[$i].';'), $text);
}
return $text;
}
ForkBBI speak only Russian :P