+ Reply to Thread
Results 1 to 6 of 6

Thread: [PHP] BBCode

  1. #1
    Synkc's Avatar
    Synkc is offline Lord Of The Keys Synkc is an unknown quantity at this point
    Join Date
    Jun 2007
    Location
    Hervey Bay, Australia
    Posts
    1,765

    [PHP] BBCode

    This is a simple PHP function to convert BBCODE style text into valid HTML. Useful for news management scripts/cms's/forums etc.

    Simple call the bbCode() function when displaying the text to the end user.

    PHP Code:
        function bbCode($text){
            
    $text str_ireplace"<BR>",    "<br />",    $text ); //Valid xHTML
            
    $text preg_replace"#\[(left|right|center)\](.+?)\[/\\1\]#is"  "<div align=\"\\1\">\\2</div>"$text ); //Aligns text ([center]text[/center], [left]text[/left], [right]text[/right]
            
    $text preg_replace"#\[(b|i|u|s)\](.+?)\[/\\1\]#is"  "<\\1>\\2</\\1>"$text ); //Makes text bold/italic/underlined/strikethrough [i]text[/i]
            
    $text preg_replace"#\[(url)\=(.+?)\](.*?)\[/\\1\]#is" "<a href=\"\\2\">\\3</a>"$text ); //Link - custom text as link ([url=address]text[/url])
            
    $text preg_replace"#\[(url)\](.*?)\[/\\1\]#is" "<a href=\"\\2\">\\2</a>"$text ); //Link - displays address as link ([url]address[/url])
        
    $text preg_replace"#\[(img)\](.*?)\[/\\1\]#is" "<img src=\"\\2\" />"$text ); //Images        
            
    return $text;
        } 
    Comments and feedback is always nice.
    Last edited by Synkc; 02-28-2008 at 01:25 AM.
    E-mail: synkc[at]x10hosting[dot]com
    Hirokima.com

  2. #2
    sunils's Avatar
    sunils is offline x10 Spammer sunils is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Chennai ,India
    Posts
    2,264

    Re: [PHP] BBCode

    Thanks for the tutorial.

    You said that it can be used for news management. in what sense it can be used
    Last edited by sunils; 02-28-2008 at 01:02 AM.
    [LEFT][B]Sunil Sankar
    -------------------------------------------------------------------------

  3. #3
    Synkc's Avatar
    Synkc is offline Lord Of The Keys Synkc is an unknown quantity at this point
    Join Date
    Jun 2007
    Location
    Hervey Bay, Australia
    Posts
    1,765

    Re: [PHP] BBCode

    By calling the bbCode() function......?
    I don't understand what you're asking...
    E-mail: synkc[at]x10hosting[dot]com
    Hirokima.com

  4. #4
    sunils's Avatar
    sunils is offline x10 Spammer sunils is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Chennai ,India
    Posts
    2,264

    Re: [PHP] BBCode

    i meant to ask. why is this function need to be called for news management scripts/cms's/forums etc.

    You said
    This is a simple PHP function to convert BBCODE style text into valid HTML. Useful for news management scripts/cms's/forums etc.

    Simple call the bbCode() function when displaying the text to the end user.
    [LEFT][B]Sunil Sankar
    -------------------------------------------------------------------------

  5. #5
    Synkc's Avatar
    Synkc is offline Lord Of The Keys Synkc is an unknown quantity at this point
    Join Date
    Jun 2007
    Location
    Hervey Bay, Australia
    Posts
    1,765

    Re: [PHP] BBCode

    I still don't know what your talking about lol.

    I said it was useful for news management scripts, cms's and forums because it converts bbCode styled blocks into html for the end-user.

    By the way, this is NOT for pre-made forums/cms's such as Joomla and phpBB; this is for custom scripts.
    Last edited by Synkc; 02-28-2008 at 02:34 AM.
    E-mail: synkc[at]x10hosting[dot]com
    Hirokima.com

  6. #6
    sunils's Avatar
    sunils is offline x10 Spammer sunils is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Chennai ,India
    Posts
    2,264

    Re: [PHP] BBCode

    Quote Originally Posted by Synkc View Post
    I still don't know what your talking about lol.

    I said it was useful for news management scripts, cms's and forums because it converts bbCode styled blocks into html for the end-user.

    By the way, this is NOT for pre-made forums/cms's such as Joomla and phpBB; this is for custom scripts.


    Thats what i was asking about, converting bbcode styled blocks into html..................

    Any way thanks
    [LEFT][B]Sunil Sankar
    -------------------------------------------------------------------------

+ Reply to Thread

Similar Threads

  1. [PHP] Alternating Table Classes..
    By Shadow121 in forum Programming Help
    Replies: 0
    Last Post: 02-20-2008, 04:39 PM
  2. [PHP] Find Nearest Quarter Hour
    By Chris S in forum Tutorials
    Replies: 0
    Last Post: 01-13-2008, 08:17 PM
  3. phpBB3 RC7 bbCode for thumbnail (thickbox)
    By onewalrus in forum Computers & Technology
    Replies: 0
    Last Post: 10-20-2007, 01:17 AM
  4. Anyone [PHP]
    By Brandon in forum The Marketplace
    Replies: 5
    Last Post: 01-25-2006, 09:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers