[PHP] BBCode

Synkc

Active Member
Messages
1,765
Reaction score
0
Points
36
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:
    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:

sunils

New Member
Messages
2,266
Reaction score
0
Points
0
Thanks for the tutorial.

You said that it can be used for news management. in what sense it can be used
 
Last edited:

Synkc

Active Member
Messages
1,765
Reaction score
0
Points
36
By calling the bbCode() function......?
I don't understand what you're asking...
 

sunils

New Member
Messages
2,266
Reaction score
0
Points
0
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.
 

Synkc

Active Member
Messages
1,765
Reaction score
0
Points
36
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:

sunils

New Member
Messages
2,266
Reaction score
0
Points
0
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
 
Top