I'm try to create function to replace [ quote][ /quote] and [quote=xxx][/quote] to a table.
I've modify some function i found on the internet to look like
Code: Select all
function bbcode_format ($str) {
$str = nl2br($str);
$str = stripslashes($str);
$simple_search = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[url\=(.*?)\](.*?)\[\/url\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[align\=(left|center|right)\](.*?)\[\/align\]/is',
'/\[img\](.*?)\[\/img\]/is',
'/\[font\=(.*?)\](.*?)\[\/font\]/is',
'/\[size\=(.*?)\](.*?)\[\/size\]/is',
'/\[color\=(.*?)\](.*?)\[\/color\]/is',
);
$simple_replace = array(
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>',
'<a href="$1">$2</a>',
'<a href="$1">$1</a>',
'<div style="text-align: $1;">$2</div>',
'<img src="$1" />',
'<span style="font-family: $1;">$2</span>',
'<span style="font-size: $1'.'px;">$2</span>',
'<span style="color: $1;">$2</span>',
);
// Do simple BBCode's
$str = preg_replace ($simple_search, $simple_replace, $str);
// Do <blockquote> BBCode
$str = bbcode_quote ($str);
return $str;
}
function bbcode_quote ($str) {
$open = '<table border=1 cellspacing=0 cellpadding=10 align=left><tr><td style=\'border: 1px dotted\'>';
$close = '</td></tr></table><br><br>';
// How often is the open tag?
preg_match_all ('/\[quote\]/i', $str, $matches);
$opentags = count($matches['0']);
// How often is the close tag?
preg_match_all ('/\[\/quote\]/i', $str, $matches);
$closetags = count($matches['0']);
// Check how many tags have been unclosed
// And add the unclosing tag at the end of the message
$unclosed = $opentags - $closetags;
for ($i = 0; $i < $unclosed; $i++) {
$str .= $close;
}
// Do replacement
$str = str_replace ('[' . 'quote]', $open, $str);
$str = str_replace ('[/' . 'quote]', $close, $str);
$str = htmlwrap($str);
return $str;
}Code: Select all
<p><strong>xxx Posted :</strong></p><br><table border=1 cellspacing=0 cellpadding=10><tr><td style=\'border: 1px dotted\'>[DATA]</td></tr></table><br>