I'm so unfamiliar with regular expression, but i spend few days on it and come out with the following..
function bbs_decode(&$message)
{
$search = array ('/(\[img=)[\'"]?(.*?)[\'"]?]/',
'/(\[img])(.*?)\[\/img]/',
'/(\[url=)[\'"]?(http:\/\/)?(.*?)[\'"]?](.*?)\[\/url]/',
'/(\[size=)(\d{0,2})](.*?)(\[\/size])/',
'/(\[color=)[\'"]?(.*)?[\'"]?](.*?)\[\/color]/',
'/\[b](.*?)\[\/b]/',
'/\[i](.*?)\[\/i]/',
'/\[u](.*?)\[\/u]/',
'/(\[quote=)(.*?)]([\s\S]*?)\[\/quote]/',
'/[\n]/'
);
$replace = array ('<img src="$2">',
'<img src="$2">',
'<a href="http://$3" target="_blank">$4</a>',
'<span style="font-size: $2pt">$3</span>',
'<span style="color: $2">$3</span>',
'<span style="font-weight: bold">$1</span>',
'<span style="font-style: italic">$1</span>',
'<span style="font-style: underline">$1</span>',
'<div align="center"><table border=0 cellspacing=2 cellpadding=2 width="85%"><tr><td><font style=" font-weight:bold"> Quote from : $2</font></td></tr><tr><td bgcolor="FFFFFF" style="border-bottom:1px solid #9a94c5; border-top:1px solid #9a94c5; border-left:1px solid #9a94c5; border-right:1px solid #9a94c5">$3</td></tr></table></div>',
'<br />'
);
echo nl2br(preg_replace($search,$replace,$message));
return $message;
}
what i'm trying to do is to create a forum...
the above code works fine if the opening tag and the closing tag of the bbs code are in same line
for example
[ color=red] red text [ /color]
but if opening tag and closing tag are in different lines then it will not work
eg.
[ color=red]
red paragraph
second red line
[ /color]
i think include /n/r somewhere inside the regular expression ...
but... i really don't know how,
can anyone please help me to solve it !!
thanx in advance ~