Results 1 to 10 of 10

Thread: BB Code?

  1. #1
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default BB Code?

    Hey,

    Does anyone know a good BB Code function that parses it no matter if it is on the same line or not.

    I currently have
    PHP Code:
    <?php
    function bb($str)
    {
    $str preg_replace('#\[b\](.*?)\[/b\]#i','<strong>$1</strong>',$str);  
    $str preg_replace('#\[i\](.*?)\[/i\]#i','<em>$1</em>',$str);
    $str preg_replace('#\[u\](.*?)\[/u\]#i','<u>$1</u>',$str);
    $str preg_replace('#\[align=(.*?)\](.*?)\[/align\]#i','<div align="$1">$2</div>',$str);
    $str preg_replace('#\[color=(.*?)\](.*?)\[/color\]#i','<font color="$1">$2</font>',$str);
    $str preg_replace('#\[font=(.*?)\](.*?)\[/font\]#i','<font face="$1">$2</font>',$str);
    $str preg_replace('#\[size=(.*?)\](.*?)\[/size\]#i','<font size="$1">$2</font>',$str);
    $str preg_replace('#\[img\](.*?)\[/img\]#i','<img src="$1" />',$str);
    $str preg_replace('#\[code\](.*?)\[/code\]#i','<fieldset><legend>Code</legend><br />$1</fieldset>',$str);  
    $str preg_replace('#\[quote\](.*?)\[/quote\]#i','<fieldset><legend>Quote</legend><br />$1</fieldset>',$str);  
    $str preg_replace('#\[quote=(.*?)\](.*?)\[/quote\]#i','<fieldset><legend>Quote - $1</legend><br />$2</fieldset>',$str);
    $str preg_replace('#\[url\](.*?)\[/url\]#i','<a href="$1" target="_blank">$1</a>',$str);
    $str preg_replace('#\[url=(.*?)\](.*?)\[/url\]#i','<a href="$1" target="_blank">$2</a>',$str);
    return 
    $str;
    }
    ?>
    However, it only works if its on the same line.

    Thanks for any help =]
    Coming and going...
    Highers are getting the better of me

  2. #2
    Join Date
    Aug 2006
    Location
    Manchester, UK
    Posts
    2,016
    Tokens
    141
    Habbo
    florx

    Latest Awards:

    Default

    I found this on google

    PHP Code:
    <?php
    function bb2html($text)
    {
      
    $bbcode = array("<"">",
                    
    "[list]""[*]""[/list]"
                    
    "[img]""[/img]"
                    
    "[b]""[/b]"
                    
    "[u]""[/u]"
                    
    "[i]""[/i]",
                    
    '[color="'"[/color]",
                    
    "[size=\"""[/size]",
                    
    '[url="'"[/url]",
                    
    "[mail=\"""[/mail]",
                    
    "[code]""[/code]",
                    
    "[quote]""[/quote]",
                    
    '"]');
      
    $htmlcode = array("&lt;""&gt;",
                    
    "<ul>""<li>""</ul>"
                    
    "<img src=\"""\">"
                    
    "<b>""</b>"
                    
    "<u>""</u>"
                    
    "<i>""</i>",
                    
    "<span style=\"color:""</span>",
                    
    "<span style=\"font-size:""</span>",
                    
    '<a href="'"</a>",
                    
    "<a href=\"mailto:""</a>",
                    
    "<code>""</code>",
                    
    "<table width=100% bgcolor=lightgray><tr><td bgcolor=white>""</td></tr></table>",
                    
    '">');
      
    $newtext str_replace($bbcode$htmlcode$text);
      
    $newtext nl2br($newtext);//second pass
      
    return $newtext;
    }
    ?>

  3. #3
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    mm. Might try that

    Looks like it might end up in unclosed tags though :S?
    Coming and going...
    Highers are getting the better of me

  4. #4
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Um i take it nobodys got any more ideas?

    -Note to MODs: Bumping my old thread uses less resources than posting new one
    Coming and going...
    Highers are getting the better of me

  5. #5
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    I have one (a whole class) but I dunno if Im allowed to give it out seems as its from a secret version of kp. ill see what he says.

  6. #6
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Thanks
    Coming and going...
    Highers are getting the better of me

  7. #7
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    I have one (a whole class) but I dunno if Im allowed to give it out seems as its from a secret version of kp. ill see what he says.
    If it's Dan's BBCode parser, he's already posted it on a forum.

  8. #8
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Quote Originally Posted by Invent View Post
    If it's Dan's BBCode parser, he's already posted it on a forum.
    Its not its a brand new one...

    Edit: Paste it here, to see if it is.
    Last edited by Blob; 23-12-2007 at 12:43 PM.

  9. #9
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    I don't have it, he just posted it on SOM.

  10. #10
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    SOM? Well, I think its new anyways. How recent was the post?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •