Logo - MyWebsolution.de
User gesamt  :  2311144
User online  :  2
KubaSeoTräume, PHP Forum, PHP Community and more ... MyWebsolution.de!
   
   
 
Registrieren Login User F.A.Q Suche Home

eingeloggt bleiben

MyWebsolution.de Foren » Tutorials » PHP BB-Code

Seite: 1 Posts pro Seite: 5 10 20
Autor Thread
28.12.2008 18:34 Uhr PHP BB-Code
030er
User
 
registriert 28.12.2008
wohnt in
Beiträge 2
hab mir das BB-Code Tutorial angeschaut
funktioniert auch alles super
PHP:

<?PHP

$text 
"blubb: [ php]<?PHP echo \"Hello world!\"; // das ist toll [ php] ?>[ /php] krass";

// http://www.mywebsolution.de/tutorials/4/page_6/show_BB-Code.html#up
$php_start "<div class=\"headline\">PHP-Code</div>".
    
"";
$php_end "";
$php = array();
preg_match_all("/\[php\](.*)\[\/php\]/siU"$text$php);
foreach(
$php[0] as $key => $value)
    {
    
$text preg_replace('#'.preg_quote($value'#').'#','[ php]'.$key.'[ /php]',$text,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)
    {
    
$text preg_replace("/\[php\]".$key."\[\/php\]/siU"$value$text);
    }
// http://www.mywebsolution.de/tutorials/4/page_6/show_BB-Code.html#up


echo $text;

?>


möchte das ganze als funktion haben (bb_php($text)) aber bekomm das einfach nicht hin :(
bin über jede Hilfe dankbar
Profil ansehen
29.12.2008 09:47 Uhr
030er
User
 
registriert 28.12.2008
wohnt in
Beiträge 2
hat sich erledigt :)
Profil ansehen
08.06.2009 21:14 Uhr
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 :P 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($linkname045-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("/(&#039;.*&#039;)/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), 07)== 'http://' OR substr(strtolower($word), 08)== 'https://' OR substr(strtolower($word), 04)=='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.
Profil ansehen
09.06.2009 22:44 Uhr
Flitze
Administrator
registriert 17.10.2006
wohnt in Eschwege
Beiträge 332
Es könnte an dieser Stelle liegen:
PHP:

<?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;
    }  
?>

Entfern mal die Leerzeichen innerhalb der Klammern von [ php] und [ /php]

Dieser Beitrag wurde am 09.06.2009 um 22:44:22 Uhr von Flitze zum 1. Mal editiert.


Profil ansehen Mail senden
22.10.2010 12:08 Uhr
clepto
User
 
registriert 08.06.2009
wohnt in
Beiträge 3
Moin, mir sind 2 sachen aufgefallen.
Wenn mann eine URL in den Text schreibt und dann direkt einen Zeilenumbruch macht
steht der <br /> TAGG zum teil mit im Link. (Zumindest bei mir so...)
Mal schaun ob's hier auch so ist.
www.google.de
Außerdem habe ich die linkLenght-Funktion ein bischen überarbeitet,
da bei einer ftp- o. https-URL dem Link ein http vorgesetzt wird.

kA obs die beste Lösung ist, aber habs so umgeschrieben
PHP:
<?php function url_lenght($treffer)
{
    
// $treffer[1] ist die URL
    
$url trim($treffer[1]);
    if(!
preg_match('/^(ftp|http|https|):\/\/\S+$/mi'$url))
            
$url "http://".$url;
    
// $treffer[2] ist der Ausgabename
    // wurde kein Name angegeben, wird die URL als Name gewählt
    
if(strlen(trim($treffer[2]))!=0)
        
$linkname $treffer[2];
    else
        
$linkname $treffer[1];
    
// legt eine maximale Länge von 50 Zeichen fest
    // Ausnahme bei [img]-Tags
    
if(strlen($linkname)>50 && !substr_count(strtolower($linkname), '[img]') && !substr_count(strtolower($linkname), '[/img]'))
        
$linkname substr($linkname045-3)."...".substr($linkname, -5);
    
// Rückgabelink
    
$ergebnis '<a href="'.$url.'" target="_blank">'.$linkname.'</a>';
    return 
$ergebnis;
?>


Funzt zumindest sehr gut bei mir :)

Dieser Beitrag wurde am 26.10.2010 um 12:11:17 Uhr von clepto zum 1. Mal editiert.
Profil ansehen
22.10.2010 12:09 Uhr
clepto
User
 
registriert 08.06.2009
wohnt in
Beiträge 3
Ok dein parser macht das nicht, aber es passiert etwas anderes...
ein blick in den Seitenquellcode zeigt an der Linkstelle das hier an.
Zitat:
<a href="http://www.google.de"www.google.de>www.go ogle.de</a><br />
Profil ansehen
Seite: 1 no reply
Powered by Pascal Landau © 2006 MyWebsolution.de
Designed by Pascal Landau © 2006 MyWebsolution.de
 
 
 
 
Home Email Impressum Disclaimer Statistik