clepto
|
User
|
|
registriert
|
08.06.2009
|
wohnt in
|
|
Beiträge
|
3
|
|
bevor ich ein neuen thread eröffne, schreib ich mal hier...
das tut is echt nice bloß bei der ausgabe für php kommt nur [ php]0[ /php]
warum? gibs da n "heufigen fehler"?
PHP:
<?php
function bbcodelinksize($treffer) {
$url = trim($treffer[1]);
if(substr($url,0,7)!= 'http://') { $url="http://".$url; }
if(strlen(trim($treffer[2]))!=0) { $linkname=$treffer[2]; }
else { $linkname=$treffer[1]; }
if(strlen($linkname)>50 AND !substr_count(strtolower($linkname), '[img]') AND !substr_count(strtolower($linkname), '[/img]')) { $linkname = substr($linkname, 0, 45-3)."...".substr($linkname, -5); }
$result = "<a href=\"".$url."\" target=\"_blank\">".$linkname."</a>";
return $result;
}
function bbcodepicsize($treffer) {
$size = @getimagesize($treffer[1]);
if ($size[0] > 400) {
$width = 400;
$height = ($size[1]/$size[0])*$width;
return " <img src=\"".$treffer[1]."\" width=\"".$width."\" height=\"".$height."\" border=\"0\"> ";
} else { return " <img src=\"".$treffer[1]."\" border=\"0\"> "; }
}
function bbcodevar($treffer) {
$str = $treffer[1];
$str = str_replace("[", "<span style=\"color:#007700\">[</span>", $str);
$str = str_replace("]", "<span style=\"color:#007700\">]</span>", $str);
// alles was zwischen single quotes ( ') steht rot hervorheben
$str = preg_replace("/('.*')/Uis", "<span style=\"color:#DD0000\">\1</span>", $str);
// den Rest blau hervorheben
$str = "<span style=\"color:#0000BB\">".$str."</span>";
return $str;
}
function smilies($str) {
$str = str_replace(':)',"<img src=\"img/smilies/emoticon_smile.png\">", $str);
$str = str_replace(':-)',"<img src=\"img/smilies/emoticon_smile.png\">", $str);
$str = str_replace('xD',"<img src=\"img/smilies/emoticon_evilgrin.png\">", $str);
$str = str_replace(':D',"<img src=\"img/smilies/emoticon_grin.png\">", $str);
$str = str_replace(':-D',"<img src=\"img/smilies/emoticon_grin.png\">", $str);
$str = str_replace(':P',"<img src=\"img/smilies/emoticon_tongue.png\">", $str);
$str = str_replace(':-P',"<img src=\"img/smilies/emoticon_tongue.png\">", $str);
$str = str_replace(';)',"<img src=\"img/smilies/emoticon_wink.png\">", $str);
$str = str_replace('^^',"<img src=\"img/smilies/emoticon_happy.png\">", $str);
$str = str_replace(':(',"<img src=\"img/smilies/emoticon_unhappy.png\">", $str);
$str = str_replace(':o',"<img src=\"img/smilies/emoticon_surprised.png\">", $str);
$str = str_replace(':waii:',"<img src=\"img/smilies/emoticon_waii.png\">", $str);
return $str;
}
function bbcode($content) {
$max_word_lenght=60;
$max_link_lenght=200;
$splitter = " ";
$lines=explode("\n", $content);
foreach($lines as $key_line => $line) {
$words = explode(" ",$line);
foreach($words as $key_word => $word) {
if(substr(strtolower($word), 0, 7)== 'http://' OR substr(strtolower($word), 0, 8)== 'https://' OR substr(strtolower($word), 0, 4)=='www.') {
$max_lenght = $max_link_lenght;
} else { $max_lenght = $max_word_lenght; }
$word = trim($word);
$word = preg_replace("/\[(.*)\]/Usi", "", $word);
if(strlen($word)>$max_lenght) {
$words[$key_word] = chunk_split($words[$key_word], $max_lenght, $splitter);
$length = strlen($words[$key_word])-strlen($splitter);
$words[$key_word] = substr($words[$key_word],0,$length);
}
}
$lines[$key_line] = implode(" ", $words);
}
$content = implode("\n", $lines);
$content=preg_replace("/\[b\](.*)\[\/b\]/Usi", "<b>\1</b>", $content);
$content=preg_replace("/\[i\](.*)\[\/i\]/Usi", "<i>\1</i>", $content);
$content=preg_replace("/\[u\](.*)\[\/u\]/Usi", "<u>\1</u>", $content);
$content=preg_replace("/\[color=(.*)\](.*)\[\/color\]/Usi", "<span color=\"\1\">\2</span>", $content);
$content=preg_replace("/\[email=(.*)\](.*)\[\/email\]/Usi", "<a href=\"mailto:\1\">\2</a>", $content);
$content=preg_replace_callback("/\[url=(.*)\](.*)\[\/url\]/Usi", 'bbcodelinksize', $content);
$content=preg_replace_callback('#(( |^)(((ftp|http|https|)://)|www.)\S+)#mi', 'bbcodelinksize', $content);
$content=preg_replace_callback("/\[img\](.*)\[\/img\]/Usi", 'bbcodepicsize', $content);
$content = preg_replace_callback("/\[var\](.*)\[\/var\]/Usi", 'bbcodevar', $content);
while(preg_match('/\[quote\](.*)\[\/quote\]/Uis', $content)) {
$width -= 10;
$quote_start = '<br><b><span color="#333333">Zitat:<span></b><br>'.
'<div style="border:solid 1px #E5E5E5; margin-left:5px; padding-left:3px; padding-right:3px; background-color:white; margin:0px auto; width:340px"><br>';
$quote_end='</div>';
$content=preg_replace("/\[quote](.*)\[\/quote\]/Uis", $quote_start."\1".$quote_end, $content);
$php_start='<br><b><u>PHP</u></b><br>'.
'<div style="border:solid 1px #E5E5E5; padding-left:3px; padding-right:3px; background-color:#ffffff; margin:0px auto; width:350px; overflow:auto; white-space:pre"><br>';
$php_end = '</div><br>';
$php = array();
preg_match_all("/\[php\](.*)\[\/php\]/siU", $content, $php);
foreach($php[0] as $key => $value){
$content=preg_replace('#'.preg_quote($value, '#').'#','[ php]'.$key.'[ /php]',$content,1);
$php[1][$key] = highlight_string($php[1][$key], TRUE);
$php[1][$key] = $php_start.$php[1][$key].$php_end;
}
foreach($php[1] as $key => $value) { $content = preg_replace("/\[php\]".$key."\[\/php\]/siU", $value, $content); }
}
$content=smilies($content);
return $content;
}
?>
habs ein klein bischen abgeändert was die bezeichnungen angeht.
|