View Single Post
Old 03-20-2008, 10:54 AM   #11 (permalink)
marxx
The Contributor
 
marxx's Avatar
 
Join Date: Sep 2007
Location: Finland
Posts: 45
Thanks: 3
marxx is on a distinguished road
Default

Well, if you end up using simple function (or someone else need help whit it) here is one simple parser.

PHP Code:
function bbcode_format($var) {
    
$search = array(
        
'/\[b\](.*?)\[\/b\]/is',                                
        
'/\[i\](.*?)\[\/i\]/is',                                
        
'/\[u\](.*?)\[\/u\]/is',
        
'/\[img\](.*?)\[\/img\]/is',
        
'/\[url\](.*?)\[\/url\]/is',
        
'/\[url\=(.*?)\](.*?)\[\/url\]/is'
        
);

    
$replace = array(
        
'<strong>$1</strong>',
        
'<em>$1</em>',
        
'<u>$1</u>',
        
'<img src="$1" />',
        
'<a href="$1">$1</a>',
        
'<a href="$1">$2</a>'
        
);

    
$var preg_replace ($search$replace$var);

    return 
$var;

usage:
PHP Code:

$text 
"This is [b]example[/b] text whit
 [url=http://www.google.com]google link[/url]"
;

echo 
bbcode_format($text); 
will look like:

This is example text whit google link.

=)
Send a message via MSN to marxx
marxx is offline  
Reply With Quote
The Following 2 Users Say Thank You to marxx For This Useful Post:
Alan @ CIT (03-23-2008), ETbyrne (03-20-2008)