[PHP] Bulletin Board Code (BBC)

Discussion in 'PHP' started by fLICKERR, Mar 27, 2012.

  1. #1
    
    <?php 
    function text2bbc($text){ 
        $find = array( 
            '~\[b\](.*?)\[/b\]~s', 
            '~\[i\](.*?)\[/i\]~s', 
            '~\[u\](.*?)\[/u\]~s', 
            '~\[size=(.*?)\](.*?)\[/size\]~s', 
            '~\[color=(.*?)\](.*?)\[/color\]~s' 
        ); 
        $replace = array( 
            '<b>$1</b>', 
            '<i>$1</i>', 
            '<span style="text-decoration:underline;">$1</span>', 
            '<span style="font-size:$1px;">$2</span>', 
            '<span style="color:$1;">$2</span>' 
        ); 
        return preg_replace($find,$replace,$text); 
    } 
    
    echo text2bbc('this is some [b]bold text[/b] and this is [color=#FF0000]Red textThis will convert Bulletin Board Code into readable HTML, good for comments, forums, etc.
    ');
    echo'<br>'; 
    echo text2bbc('this text is [i]italic[/i] and this is not'); 
    echo'<br>'; 
    echo text2bbc('here we have [u]underlined[/u] text'); 
    echo'<br>'; 
    echo text2bbc('this is [size=24]24px[/size] font'); 
    ?>
    
    PHP:

     
    fLICKERR, Mar 27, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Also named UBB :)

    But why not add more common used tags? if you want to share hulpfull snippets!
     
    EricBruggema, Mar 27, 2012 IP