<?php
function bb_code($bb_code, $string)
{
$pattern = Array();
$pattern['smile'] = '!\[:([0-9]{2}):\]!s';
$pattern['b'] = '!\[b\](.*)\[/b\]!iUm';
$pattern['i'] = '!\[i\](.*)\[/i\]!iUm';
$pattern['u'] = '!\[u\](.*)\[/u\]!iUm';
$pattern['quote'] = '!\[quote\](.*)\[/quote\]!iUm';
$pattern['code'] = '!\[code\](.*)\[/code\]!iUm';
$pattern['size'] = '!\[size=([0-9]{2})\](.*)\[/size\]!iUm';
$pattern['font'] = '!\[font=([0-9a-z -_/\.]+)\](.*)\[/font\]!iUm';
$pattern['img'] = '!\[img\](.*)\[/img\]!iUs';
$pattern['color1'] = '!\[color=(#[0-9a-f]{6})\](.*)\[/color\]!iUm';
$pattern['color2'] = '!\[color=([black|maroon|green|olive|navy|purple|teal|silver|gray|red|lime|yellow|blue|fuchsia|aqua|white])\](.*)\[/color\]!iUm';
$pattern['url1'] = '!\[url\](http://[0-9a-z-_/%=&?\[\]#+:\.]+)\[/url\]!iUs';
$pattern['url2'] = '!\[url=(http://[0-9a-z-_/%=&?\[\]#+:\.]+)\](.*)\[/url\]!iUs';
$replace = Array();
$replace['smile'] = '<img src="bilder/smilies/smile$1.gif" alt="::$1::">';
$replace['b'] = '<span class="fett">$1</span>';
$replace['i'] = '<span class="kursiv">$1</span>';
$replace['u'] = '<span class="unterstrichen">$1</span>';
$replace['quote'] = '<br><span class="klein">Zitat:</span><br><div class="zitat">$1</div>';
$replace['code'] = '<br><span class="klein">Code:</span><br><div class="code">$1</div>';
$replace['size'] = '<span style="font-size:$1px;">$2</span>';
$replace['color'] = '<span style="color:$1;">$2</span>';
$replace['font'] = '<span style="font-family:$1:">$2</span>';
$replace['img'] = '<img src="$1" alt="$1">';
$replace['color'] = '<span style="color:$2;">$4</span>';
$replace['url1'] = '<a href="$1" target="_blank">$1</a>';
$replace['url2'] = '<a href="$1" target="_blank">$2</a>';
if($bb_code == 'url')
return preg_replace($pattern['url1'], $replace['url1'], preg_replace($pattern['url2'], $replace['url2'], $string));
else if($bb_code == 'color')
return preg_replace($pattern['color2'], $replace['color'], preg_replace($pattern['color1'], $replace['color'], $string));
else
return preg_replace($pattern[$bb_code], $replace[$bb_code], $string);
}
?>