Thread: BB Code
View Single Post
Old 10-25-2007, 09:40 AM   #7 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default

Nope, I'm lost lol :(

What I have at the minute is:
PHP Code:
function BBCode($text){
$BBCode = array("&" => "&",
"<" => "&lt;",
">" => "&gt;",
"[b]" => "<b>",
"[/b]" => "</b>",
"[i]" => "<i>",
"[/i]" => "</i>",
"[u]" => "<u>",
"[/u]" => "</u>",
"[img]" => "<img src='",
"[/img]" => "'>");
$parsedtext str_replace(array_keys($BBCode), array_values($BBCode), $text);
return 
$parsedtext;

That works fine but I want to change it to do it your way.

I've tried:

PHP Code:
function BBcode($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;


Although I get no errors with the above code the bb tags aren't replaced, where am I going wrong?
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote