<?
function parse($str, $html = 0, $bbcode = 1, $url = 1, $email = 1, $img = 1, $br = 1, $uml = 1) {
$str = trim($str);
$str = preg_replace('/\S{60}/', '\0 ', $str);
if ($html == 0) {
$str = htmlspecialchars($str);
$str = htmlentities($str);
}
if ($bbcode == 1) {
$str = preg_replace('=\[b\](.*)\[/b\]=Uis',
'<span style="font-weight:bold;">\\1</span>',
$str);
$str = preg_replace('=\[i\](.*)\[/i\]=Uis',
'<span style="font-style:italic;">\\1</span>',
$str);
$str = preg_replace('=\[u\](.*)\[/u\]=Uis',
'<span style="text-decoration:underline;">\\1</span>',
$str);
# Smilies
$str = str_replace(':cool:', '<img src="images/smilies/cool.gif" />', $str);
$str = str_replace(':freu:', '<img src="images/smilies/freu.gif" />', $str);
$str = str_replace(':woow:', '<img src="images/smilies/woow.gif" />', $str);
# Zitate
$str = preg_replace('=\[quote\](.*)\[/quote\]=Uis','<p>Zitat:</p><div class="zitat"><pre>\\1</pre></div>',$str);
# Code
$str = preg_replace('=\[code\](.*)\[/code\]=Uis','<p>Code:</p><div class="code"><pre>\\1</pre></div>', $str);
# PHP Code
$str = preg_replace('=\[php\](.*)\[/php\]=Uis','<p>PHP Code:</p><div class="code"><pre>\\1</pre></div>',$str);
}
if ($url == 1) {
//Aus http://url wird
$urlsuch[]="/([^]_a-z0-9-=\"'\/])((https?|ftp):\/\/|www\.)([^ \r\n\(\)\^\$!`\"'\|\[\]\{\}<>]*)/si";
$urlsuch[]="/^((https?|ftp):\/\/|www\.)([^ \r\n\(\)\^\$!`\"'\|\[\]\{\}<>]*)/si";
$urlreplace[]="\\1[url]\\2\\4[/url]";
$urlreplace[]="[url]\\1\\3[/url]";
}
if ($email == 1) {
//Aus [email]klaus@mustermann.de[/email] wird [email]klaus@mustermann.de [/email]
$emailsuch[]="/([\s])([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/si";
$emailsuch[]="/^([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/si";
$emailreplace[]="\\1[email]\\2[/email]";
$emailreplace[]="[email]\\0[/email]";
$str = preg_replace($urlsuch, $urlreplace, $str);
if (strpos($str, "@"))
{
$str = preg_replace($emailsuch, $emailreplace, $str);
}
}
if ($url == 1) {
//Die url's werden zu Links
$str = preg_replace("/\[url\]www.(.*?)\[\/url\]/si", "<a target=\"_blank\" href=\"http://www.\\1\">www.\\1</a>", $str);
$str = preg_replace("/\[url\](.*?)\[\/url\]/si", "<a target=\"_blank\" href=\"\\1\">\\1</a>", $str);
$str = preg_replace("/\[url=www.(.*?)\](.*?)\[\/url\]/si", "<a target=\"_blank\" href=\"http://www.\\1\">\\2</a>", $str);
$str = preg_replace("/\[url=(.*?)\](.*?)\[\/url\]/si", "<a target=\"_blank\" href=\"\\1\">\\2</a>", $str);
}
if ($email == 1) {
//E-Mail Adressen werden zu links
$str = preg_replace("/\[email\](.*?)\[\/email\]/si", "<a href=\"mailto:\\1\">\\1</a>", $str);
$str = preg_replace("/\[email=(.*?)\](.*?)\[\/email\]/si", "<a href=\"mailto:\\1\">\\2</a>", $str);
}
if ($img == 1) {
// wird als Bild angezeigt
$str = preg_replace( '#\[img\](.*?)\[/img\]#sie', "'<img src=\"'.str_replace(' ', '', '\\1').'\" border=\"0\" alt=\"\" />'" , $str );
}
if ($br == 1) {
$str = nl2br($str);
}
if ($uml == 1) {
$str = str_replace( "[ä]" , "ä" , $str );
$str = str_replace( "[ü]" , "ü" , $str );
$str = str_replace( "[ö]" , "ö" , $str );
$str = str_replace( "[Ä]" , "Ä" , $str );
$str = str_replace( "[Ü]" , "Ü" , $str );
$str = str_replace( "[Ö]" , "Ö" , $str );
$str = str_replace( "[ß]" , "ß" , $str );
}
return $str;
}
?>