where can i get php code for BBcode

Discussion in 'PHP' started by Dirty-Rockstar, Aug 29, 2007.

  1. #1
    
    $bbcode = array(
    						'/\[b\](.*?)\[\/b\]/is',                                
    						'/\[i\](.*?)\[\/i\]/is',                                
    						'/\[u\](.*?)\[\/u\]/is'
    						);
    
    $bbcode_replace = array(
    						'<strong>$1</strong>',
    						'<em>$1</em>',
    						'<u>$1</u>'
    						);
    
    PHP:
    i want to build onto this. but im a little lost. only thing i could add would be <i> </i>. and basic colors and maybe quotes. can someone help me with to some code so i can add images and url links. i can figure the rest out myself. I think....

    TYVM
     
    Dirty-Rockstar, Aug 29, 2007 IP
  2. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #2
    what you got there already is pretty close mate

    if you wanted to do URLs etc you could do
    
    $string = 'April 15, 2003';
    $pattern = '/(\w+) (\d+), (\d+)/i';
    $replacement = '${1}1,$3';
    
    $string = '[link=www.blah.com]anchor text[/link]';
    $pattern = '/\[link=(.+)\](.*)\[\/url\]/i';
    $replacement = '<a href="$1">$2</a>';
    
    echo preg_replace($pattern, $replacement, $string);
    
    Code (markup):
    Thatll pretty much work, not very neat but itll work
    Note I used "link" instead of "url" else DP would have made them into actual links :)
    you can copy it and modify slightly for images etc

    But your normal str_replace will work just fine for the simpler ones
     
    m0nkeymafia, Aug 29, 2007 IP