1
function BBCode($Text)
2
{
3
// Replace any html brackets with HTML Entities to prevent executing HTML or script
4
// Don't use strip_tags here because it breaks [url] search by replacing & with amp
5
$Text = str_replace("<", "<", $Text);
6
$Text = str_replace(">", ">", $Text);
7
8
9
// Set up the parameters for a URL search string
10
$URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
11
// Set up the parameters for a MAIL search string
12
$MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@";
13
14
//Non BB URL Search
15
//$Text = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href=\"\\1://\\2\\3\" target=\"_blank\" target=\"_new\">\\1://\\2\\3</a>", $Text);
16
//$Text = eregi_replace("(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $Text);
17
if (substr($Text, 0, 7) == "http://") {
18
$Text = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
19
"<a href=\"\\1://\\2\\3\">\\1://\\2\\3</a>", $Text);
20
// Convert new line chars to html <br /> tags
21
$Text = nl2br($Text);
22
} else {
23
// Perform URL Search
24
$Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/",
25
'<a href="javascript:go(\'$1\',\'new\')">$1</a>', $Text);
26
$Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])",
27
'<a href="javascript:go(\'$1\',\'new\')">$2</a>', $Text);
28
//$Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '<a href="$1" target="_blank">$2</a>', $Text);
29
// Convert new line chars to html <br /> tags
30
$Text = nl2br($Text);
31
}
32
// Perform MAIL Search
33
$Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])",
34
'<a href="mailto:$1">$1</a>', $Text);
35
$Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/",
36
'<a href="mailto:$1">$2</a>', $Text);
37
38
// Check for bold text
39
$Text = preg_replace("(\[b\](.+?)\[\/b])is", '<span class="bold">$1</span>', $Text);
40
41
// Check for Italics text
42
$Text = preg_replace("(\[i\](.+?)\[\/i\])is", '<span class="italics">$1</span>',
43
$Text);
44
45
// Check for Underline text
46
$Text = preg_replace("(\[u\](.+?)\[\/u\])is",
47
'<span class="underline">$1</span>', $Text);
48
49
// Check for strike-through text
50
$Text = preg_replace("(\[s\](.+?)\[\/s\])is",
51
'<span class="strikethrough">$1</span>', $Text);
52
53
// Check for over-line text
54
$Text = preg_replace("(\[o\](.+?)\[\/o\])is", '<span class="overline">$1</span>',
55
$Text);
56
57
// Check for colored text
58
$Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is", "<span style=\"color: $1\">$2</span>",
59
$Text);
60
61
// Check for sized text
62
$Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is", "<span style=\"font-size: $1px\">$2</span>",
63
$Text);
64
65
// Check for list text
66
$Text = preg_replace("/\[list\](.+?)\[\/list\]/is",
67
'<ul class="listbullet">$1</ul>', $Text);
68
$Text = preg_replace("/\[list=1\](.+?)\[\/list\]/is",
69
'<ul class="listdecimal">$1</ul>', $Text);
70
$Text = preg_replace("/\[list=i\](.+?)\[\/list\]/s",
71
'<ul class="listlowerroman">$1</ul>', $Text);
72
$Text = preg_replace("/\[list=I\](.+?)\[\/list\]/s",
73
'<ul class="listupperroman">$1</ul>', $Text);
74
$Text = preg_replace("/\[list=a\](.+?)\[\/list\]/s",
75
'<ul class="listloweralpha">$1</ul>', $Text);
76
$Text = preg_replace("/\[list=A\](.+?)\[\/list\]/s",
77
'<ul class="listupperalpha">$1</ul>', $Text);
78
$Text = str_replace("[*]", "<li>", $Text);
79
80
// Check for font change text
81
$Text = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])", "<span style=\"font-family: $1;\">$2</span>",
82
$Text);
83
84
// Declare the format for [code] layout
85
$CodeLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
86
<tr>
87
<td class="quotecodeheader"> Code:</td>
88
</tr>
89
<tr>
90
<td class="codebody">$1</td>
91
</tr>
92
</table>';
93
// Check for [code] text
94
$Text = preg_replace("/\[code\](.+?)\[\/code\]/is", "$CodeLayout", $Text);
95
96
// Declare the format for [quote] layout
97
$QuoteLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
98
<tr>
99
<td class="quotecodeheader"> Quote:</td>
100
</tr>
101
<tr>
102
<td class="quotebody">$1</td>
103
</tr>
104
</table>';
105
106
// Check for [quote] text
107
$Text = preg_replace("/\[quote\](.+?)\[\/quote\]/is", "$QuoteLayout", $Text);
108
109
// Images
110
//
111
$Text = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="/$1">', $Text);
112
113
// [img=widthxheight]image source[/img]
114
$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/",
115
'<img src="/$3" height="$2" width="$1">', $Text);
116
117
return $Text;
118
}
BBCode CSS
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
BBCode CSS
1
}
Then justPHP Code:
1
echo BBCode($string_to_convert);