bbcode help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
patty07
Forum Newbie
Posts: 8
Joined: Sat Feb 23, 2008 2:14 am

bbcode help

Post by patty07 »

Can anyone figure out how to add list to the below code.
Such as bullers, letters or numbers ?

I been trying and trying and no such luck.

Code: Select all

 
function bbcode_format ($str, $removeTags = TRUE) { 
    $str = $removeTags ? strip_tags($str) : htmlentities($str); 
    $str = nl2br($str); 
 
    $simple_search = array( 
                '/\[border\](.*?)\[\/border\]/is',    
                '/\[hr\]/is',
                '/\[s\](.*?)\[\/s\]/is',                                                 
                '/\[align\](.*?)\[\/align\]/is',                                                 
                '/\[b\](.*?)\[\/b\]/is',                                 
                '/\[i\](.*?)\[\/i\]/is',                                 
                '/\[u\](.*?)\[\/u\]/is',                                 
                '/\[url\=(.*?)\](.*?)\[\/url\]/is',                          
                '/\[url\](.*?)\[\/url\]/is',                              
                '/\[align\=(left|center|right)\](.*?)\[\/align\]/is', 
                '/\[imgwl\](.*?)\[\/imgwl\]/is',//image left wrap text 
                '/\[imgwr\](.*?)\[\/imgwr\]/is',//image right wrap text                                      
                '/\[img\](.*?)\[\/img\]/is',   
                '/\[mail\=(.*?)\](.*?)\[\/mail\]/is',                     
                '/\[mail\](.*?)\[\/mail\]/is',                             
                '/\[font\=(.*?)\](.*?)\[\/font\]/is',                     
                '/\[size\=(.*?)\](.*?)\[\/size\]/is',                     
                '/\[color\=(.*?)\](.*?)\[\/color\]/is',
                '/\[bgcolor\=(.*?)\](.*?)\[\/bgcolor\]/is',
                '/\[p\](.*?)\[\/p\]/is',                                                          
                ); 
 
    $simple_replace = array( 
                '<fieldset>$1</fieldset>',                    
                '<hr>',
                '<strike>$1</strike>',                
                '<div style="text-align: $1;">$2</div>',                  
                '<strong>$1</strong>', 
                '<em>$1</em>', 
                '<u>$1</u>', 
                '<a href="$1">$2</a>', 
                '<a href="$1">$1</a>', 
                '<div style="text-align: $1;">$2</div>', 
                '<img src="$1" ALIGN="left">', //image left wrap text
                '<img src="$1" ALIGN="right">', //image right wrap text                                           
                '<img src="$1"/>', 
                '<a href="mailto:$1">$2</a>', 
                '<a href="mailto:$1">$1</a>', 
                '<span style="font-family: $1;">$2</span>', 
                '<span style="font-size: $1;">$2</span>', 
                '<span style="color: $1;">$2</span>',
                '<span style="background: $1;">$2</span>',  
                '<p>$1</p>',                
                ); 
 
    // Do simple BBCode's 
    $str = preg_replace ($simple_search, $simple_replace, $str); 
 
    // Do <blockquote> BBCode 
    $str = bbcode_quote ($str); 
//$str = nl2br($str);
    return $str; 
} 
 
 
 
function bbcode_quote ($str) { 
    $open = '<blockquote>'; 
    $close = '</blockquote>'; 
 
    // How often is the open tag? 
    preg_match_all ('/\[quote\]/i', $str, $matches); 
    $opentags = count($matches['0']); 
 
    // How often is the close tag? 
    preg_match_all ('/\[\/quote\]/i', $str, $matches); 
    $closetags = count($matches['0']); 
 
    // Check how many tags have been unclosed 
    // And add the unclosing tag at the end of the message 
    $unclosed = $opentags - $closetags; 
    for ($i = 0; $i < $unclosed; $i++) { 
        $str .= '</blockquote>'; 
    } 
 
    // Do replacement 
    $str = str_replace ('[' . 'quote]', $open, $str); 
    $str = str_replace ('[/' . 'quote]', $close, $str); 
    return $str; 
} 
 
 
Post Reply