Maverfax told me to make one, so I did.

PHP Code:
<?php
/*************************************************
/*                                               *
/*     Author: Adam Višarsson                    *
/*     Project: Learning PHP 8)                  *
/*                                               *
/*      bbcode.php - BBCode system.              *
/*                                               *
/************************************************/
function bbcode($text) {
    
    
$text strip_tags($text'<br />');
    
    
$search = array('/\[b\](.*?)\[\/b\]/i',
                    
'/\[i\](.*?)\[\/i\]/i',
                    
'/\[u\](.*?)\[\/u\]/i',
                    
'/\[url=(.*?)\](.*?)\[\/url\]/i',
                    
'/\[code\](.*?)\[\/code\]/i',
                    
'/\[img\](.*?)\[\/img\]/i',
                    
'/\:D/i',
                    
'/\:P/i',
                    
'/\:\)/i',
                    
'/\:\(/i',);
                    
    
$h_toda_tml = array('<strong>$1</strong>',
                      
'<i>$1</i>',
                      
'<u>$1</u>',
                      
'<a href="$1">$2</a>',
                      
'<code>$1</code>',
                      
'<img src="$1" alt="image" />',
                      
'<img src="http://septimuswow.com/forums/public/style_emoticons/default/biggrin.gif" alt="grin" />',
                      
'<img src="http://septimuswow.com/forums/public/style_emoticons/default/tongue.gif" alt="tongue" />',
                      
'<img src="http://septimuswow.com/forums/public/style_emoticons/default/smile.gif" alt="smile" />',
                      
'<img src="http://septimuswow.com/forums/public/style_emoticons/default/sad.gif" alt="sad" />',);

    
$text preg_replace($search$h_toda_tml$text);
    
    return 
$text;    
}
?>
Go wild, make your own arrays \o/, don't forget to change the smiley urls if you want to have your own.

How to install this?
First of all your page must include the page/script holding the bbcode system, if you save the above code as bbcode.php, you can include it like this:
PHP Code:
<?php include('bbcode.php');?>
How to use it?
To make stuff display using the BBcode system in the right BBcodes, you need to echo it by doing this:
PHP Code:
<?php echo bbcode('Hello guise, this text is [B]Bold[/B]! And this is [U]Underlined[/U]');?>
That would output:
Hello guise, this text is Bold! And this is Underlined


- CREDITS TO Pingue 8)




› See More: [PHP] BBCode System