Thread: BB Code
View Single Post
Old 10-25-2007, 08:30 AM   #5 (permalink)
bluesaga
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

You do need to be able to understand preg pattern matching to be able to understand this, but something like:

PHP Code:

function BBParser($szInput)
{

 
$aBBPattern = array(
                     
'[b](.*?)[/b]' => '<b>\\1</b>',
                     
'[i](.*?)[/i]' => '<i>\\1</i>',
                     
'[url=([^\]+?)](.*?)[/url]' => '<a href="\\1">\\2</a>'
                     
);

 foreach( 
$aBBPattern as $szKey => $szValue )
 {
    
$szPattern '/'preg_quote$szKey'/' ) .'/is';
    
$szInput    preg_replace$szPattern$szValue$szInput );
 }

 return 
$szInput;


Remember this isnt tested, but the theory is there :)
bluesaga is offline  
Reply With Quote