Code:
<?php
function output_post ($post) {
//Make safe any html
$post_no_html = htmlspecialchars($post);
$post_abridged = chop($post_no_html);
$code_treated = preg_replace_callback(
"/\[code\](.+?)\[\/code\]/s",
create_function(
'$matches',
'$regex[0] = "[";
$regex[1] = "]";
$replace[0] = "[";
$replace[1] = "]";
ksort($regex);
ksort($replace);
$treated = str_replace($regex, $replace, $matches[1]);
$output = "<table class=\"code\"><tr><td>Code:</td></tr><tr><td class=\"code_box\">$treated</td></tr></table>";
return $output;'),
$post_abridged);
$bbcode_regex = array(0 => '/\[b\](.+?)\[\/b\]/s',
1 => '/\[i\](.+?)\[\/i\]/s',
2 => '/\[u\](.+?)\[\/u\]/s',
3 => '/\[quote\](.+?)\[\/quote\]/s',
4 => '/\[quote\=(.+?)](.+?)\[\/quote\]/s',
5 => '/\[url\](.+?)\[\/url\]/s',
6 => '/\[url\=(.+?)\](.+?)\[\/url\]/s',
7 => '/\[img\](.+?)\[\/img\]/s',
8 => '/\[img height\=(.+?)\](.+?)\[\/img\]/s',
9 => '/\[img width\=(.+?)\](.+?)\[\/img\]/s',
10 => '/\[img width\=(.+?) height\=(.+?)\](.+?)\[\/img\]/s',
11 => '/\[img height\=(.+?) width\=(.+?)\](.+?)\[\/img\]/s',
12 => '/\[color\=(.+?)\](.+?)\[\/color\]/s',
13 => '/\[size\=(.+?)\](.+?)\[\/size\]/s',
14 => '/\[tt\](.+?)\[\/tt\]/s',
15 => '/\[code\](.+?)\[\/code\]/s',
16 => '/\[sup\](.+?)\[\/sup\]/s',
17 => '/\[sub\](.+?)\[\/sub\]/s',
18 => '/\[list\](.+?)\[\/list\]/s',
19 => '/\[list\=(.+?)\](.+?)\[\/list\]/s',
20 => '/\[li\](.+?)\[\/li\]/s');
$bbcode_replace = array(0 => '<b>$1</b>',
1 => '<i>$1</i>',
2 => '<u>$1</u>',
3 => '<table class="p_quote"><tr><td>Quote:</td></tr><tr><td class="p_quote_box">$1</td></tr></table>',
4 => '<table class="p_quote"><tr><td>$1 said:</td></tr><tr><td class="p_quote_box">$2</td></tr></table>',
5 => '<a href="$1">$1</a>',
6 => '<a href="$1">$2</a>',
7 => '<img src="$1" alt="User submitted image" title="User submitted image"/>',
8 => '<img height="$1" src="$2" alt="" />',
9 => '<img width="$1" src="$2" alt="" />',
10 => '<img width="$1" height="$2" src="$3" alt="" />',
11 => '<img height="$1" width="$2" src="$3" alt="" />',
12 => '<span style="color:$1">$2</span>',
13 => '<span style="font-size:$1">$2</span>',
14 => '<tt>$1</tt>',
15 => '<code>$1</code>',
16 => '<sup>$1</sup>',
17 => '<sub>$1</sub>',
18 => '<ul>$1</ul>',
19 => '<ul style="list-style-type:$1">$2</ul>',
20 => '<li>$1</li>');
ksort($bbcode_regex);
ksort($bbcode_replace);
//preg_replace to convert all remaining bbCode tags
$post_bbcode_treated = preg_replace($bbcode_regex, $bbcode_replace, $code_treated);
$post_with_br = nl2br($post_bbcode_treated);
echo $post_with_br;
};
?>
Bookmarks