03-20-2008, 10:54 AM
|
#11 (permalink)
|
|
The Contributor
Join Date: Sep 2007
Location: Finland
Posts: 45
Thanks: 3
|
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.
=)
|
|
|