UBB parser!
Code (php)
1
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
119
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
119
<?php
// Highlight functies
public function phphighlite_replace($code) {
$code = trim(str_replace("\\\"", "\"", $code));
$code = str_replace("\\\"","\"",$code);
if(empty($code)) {
return " ";
} else {
array_push($GLOBALS['phphighlite'], $code);
return "".(count($GLOBALS['phphighlite'])-1)."";
}
}
public function phphighlite($id, $fixed=1) {
$code = $GLOBALS['phphighlite'][$id];
$splitted = explode("\n", $code);
$grootte = count($splitted)+1;
if(!strpos($code,"<?") && substr($code,0,2)!="<?") {
$code="<?".trim($code)."?>";
$addedtags=1;
}
ob_start();
$oldlevel=error_reporting(0);
highlight_string($code);
error_reporting($oldlevel);
$buffer = ob_get_contents();
ob_end_clean();
if(!empty($addedtags)) {
$openingpos = strpos($buffer,'<?');
$closingpos = strrpos($buffer, '?');
$buffer = substr($buffer, 0, $openingpos).substr($buffer, $openingpos+5, $closingpos-($openingpos+5)).substr($buffer, $closingpos+5);
}
$page_popup = "";
$return = $buffer;
return $return;
}
public function ubb_code($string) {
// Code
$GLOBALS['phphighlite'] = array("dummy");
$string = preg_replace("_<\?(.*?)\?>_ise","self::phphighlite_replace('<? \\1 ?>')",$string);
#$string = preg_replace("_\[code\](.*?)\[/code\]_ise","phphighlite_replace('\\1')",$string);
// HTML codes wegwerken
$string = htmlspecialchars($string);
// Enters maken
$string = nl2br($string);
// Cursief
$string = preg_replace("#\[i\](.+?)\[/i\]#is","<i>\\1</i>",$string);
// Onderstreept
$string = preg_replace("#\[u\](.+?)\[/u\]#is","<u>\\1</u>",$string);
// Vetgedrukt
$string = preg_replace("#\[b\](.+?)\[/b\]#is","<b>\\1</b>",$string);
// Doorstreept
$string = preg_replace("#\[s\](.+?)\[/s\]#is","<s>\\1</s>",$string);
// Links maken met behulp van tags
$string = preg_replace("#\[url\](http|ftp)(.+?)\[/url\]#is","<a href=\"\\1\\2\" target=\"_blank\">\\1\\2</a>",$string);
$string = preg_replace("#\[url\](mailto:)(.+?)\[/url]#is","<a href=\"\\1\\2\" target=\"_blank\">\\2</a>",$string);
$string = preg_replace("#\[mail\](.+?)\[/mail]#is","<a href=\"mailto:\\1\" target=\"_blank\">\\1</a>",$string);
$string = preg_replace("#\[url\](.+?)\[/url\]#is","<a href=\"http://\\1\" target=\"_blank\">\\1</a>",$string);
$string = preg_replace("#\[url=(http|ftp|mailto)(.+?)\](.+?)\[/url\]#is","<a href=\"\\1\\2\" target=\"_blank\">\\3</a>",$string);
$string = preg_replace("#\[url=(.+?)\](.+?)\[/url\]#is","<a href=\"http://\\1\" target=\"_blank\">\\2</a>",$string);
// Automatisch links maken
$string = eregi_replace("(^|[\n\r\t])((http(s?)://)(www\.)?([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)", "<a href=\"\\2\"target=\"_blank\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])((http(s?)://)(www\.)?([a-z0-9_-]+([a-z0-9_-]+)+)(/[^/ \n\r]*)*)", "<a href=\"\\2\"target=\"_blank\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])([a-z_-][a-z0-9\._-]*@[a-z0-9_-]+(\.[a-z0-9_-]+)+)","<a href=\"mailto:\\2\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])(www\.([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"http://\\2\" target=\"_blank\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])(www\.([a-z0-9_-]+([a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"http://\\2\" target=\"_blank\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])(ftp://([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"\\2\" target=\"_blank\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])(ftp://([a-z0-9_-]+([a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"\\2\" target=\"_blank\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])(ftp\.([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"\\2\" target=\"_blank\">\\2</a>",$string);
// Quote
$string = preg_replace("#\[quote\](.+?)\[/quote\]#is","<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"3%\"> </td><td><small>Quote</small></td></tr><tr><td width=\"3%\"> </td><td style=\"border: 1px solid #232850;\"><table><tr><td>\\1</td></tr></table></td></tr></table>",$string);
$string = preg_replace("#\[quote=(.+?)\](.+?)\[/quote\]#is","<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"3%\"> </td><td><small>Quote: <b>\\1</b></small></td></tr><tr><td width=\"3%\"> </td><td style=\"border: 1px solid #232850;\"><table><tr><td>\\2</td></tr></table></td></tr></table>",$string);
// Plaatjes
$string = preg_replace("#\[img\](http)(.+?)\[/img\]#is","<img src=\"\\1\\2\" alt=\"Plaatje\" title\"Plaatje\" />",$string);
$string = preg_replace("#\[img\](.+?)\[/img\]#is","<img src=\"http://\\1\" alt=\"Plaatje\" title=\"Plaatje\" />",$string);
// Kleur
$string = preg_replace("#\[color=(.+?)\](.+?)\[/color\]#is","<font color=\"\\1\">\\2</font>",$string);
// Grootte
$string = preg_replace("#\[size=(.+?)\](.+?)\[/size\]#is","<font size=\"\\1\">\\2</font>",$string);
// Smileys
$string = str_replace(":)","<img src=\"images/smilies/smile.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("8|","<img src=\"images/smilies/huh.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":o","<img src=\"images/smilies/ohmy.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(";)","<img src=\"images/smilies/wink.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":P","<img src=\"images/smilies/tongue.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":D","<img src=\"images/smilies/biggrin.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("8)","<img src=\"images/smilies/cool.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("*-)","<img src=\"images/smilies/rolleyes.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":?","<img src=\"images/smilies/dry.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":@","<img src=\"images/smilies/mad.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":(","<img src=\"images/smilies/sad.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("8-)","<img src=\"images/smilies/unsure.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":|","<img src=\"images/smilies/blink.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("|:-|","<img src=\"images/smilies/ph34r.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":/","<img src=\"images/smilies/happy.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("|-)","<img src=\"images/smilies/sleep.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("(l)","<img src=\"images/smilies/wub.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":s","<img src=\"images/smilies/wacko.gif\" alt=\"Smilie\" />",$string);
// Code
$string = preg_replace("_\[code\]([0-9])\[/code\]_ise", "self::phphighlite('\\1')", $string);
// Return
return $string;
}
?>
Dat is de UBB parser die ik gebruik, hij is gemaakt door Jorik.
Maar nu 1 probleem bij mij voegt hij \" toe alleen bij de eerste doet hij dat niet, en daardoor wordt alles na de 2de " rood..... En ik ben al heeel lang bezig met die UBB parsers maar het wil maar niet lukken weet iemand van jullie mijn fout?
Of kan iemand de ubb parser van phphulp posten, want volgens mij is die wel goed(A)
[edit]php tags vergeten:S, en er kwam een error in de ubb parser van phphulp, toch niet zo goed als ik dacht(A):P[/edit]
// Highlight functies
public function phphighlite_replace($code) {
$code = trim(str_replace("\\\"", "\"", $code));
$code = str_replace("\\\"","\"",$code);
if(empty($code)) {
return " ";
} else {
array_push($GLOBALS['phphighlite'], $code);
return "".(count($GLOBALS['phphighlite'])-1)."";
}
}
public function phphighlite($id, $fixed=1) {
$code = $GLOBALS['phphighlite'][$id];
$splitted = explode("\n", $code);
$grootte = count($splitted)+1;
if(!strpos($code,"<?") && substr($code,0,2)!="<?") {
$code="<?".trim($code)."?>";
$addedtags=1;
}
ob_start();
$oldlevel=error_reporting(0);
highlight_string($code);
error_reporting($oldlevel);
$buffer = ob_get_contents();
ob_end_clean();
if(!empty($addedtags)) {
$openingpos = strpos($buffer,'<?');
$closingpos = strrpos($buffer, '?');
$buffer = substr($buffer, 0, $openingpos).substr($buffer, $openingpos+5, $closingpos-($openingpos+5)).substr($buffer, $closingpos+5);
}
$page_popup = "";
$return = $buffer;
return $return;
}
public function ubb_code($string) {
// Code
$GLOBALS['phphighlite'] = array("dummy");
$string = preg_replace("_<\?(.*?)\?>_ise","self::phphighlite_replace('<? \\1 ?>')",$string);
#$string = preg_replace("_\[code\](.*?)\[/code\]_ise","phphighlite_replace('\\1')",$string);
// HTML codes wegwerken
$string = htmlspecialchars($string);
// Enters maken
$string = nl2br($string);
// Cursief
$string = preg_replace("#\[i\](.+?)\[/i\]#is","<i>\\1</i>",$string);
// Onderstreept
$string = preg_replace("#\[u\](.+?)\[/u\]#is","<u>\\1</u>",$string);
// Vetgedrukt
$string = preg_replace("#\[b\](.+?)\[/b\]#is","<b>\\1</b>",$string);
// Doorstreept
$string = preg_replace("#\[s\](.+?)\[/s\]#is","<s>\\1</s>",$string);
// Links maken met behulp van tags
$string = preg_replace("#\[url\](http|ftp)(.+?)\[/url\]#is","<a href=\"\\1\\2\" target=\"_blank\">\\1\\2</a>",$string);
$string = preg_replace("#\[url\](mailto:)(.+?)\[/url]#is","<a href=\"\\1\\2\" target=\"_blank\">\\2</a>",$string);
$string = preg_replace("#\[mail\](.+?)\[/mail]#is","<a href=\"mailto:\\1\" target=\"_blank\">\\1</a>",$string);
$string = preg_replace("#\[url\](.+?)\[/url\]#is","<a href=\"http://\\1\" target=\"_blank\">\\1</a>",$string);
$string = preg_replace("#\[url=(http|ftp|mailto)(.+?)\](.+?)\[/url\]#is","<a href=\"\\1\\2\" target=\"_blank\">\\3</a>",$string);
$string = preg_replace("#\[url=(.+?)\](.+?)\[/url\]#is","<a href=\"http://\\1\" target=\"_blank\">\\2</a>",$string);
// Automatisch links maken
$string = eregi_replace("(^|[\n\r\t])((http(s?)://)(www\.)?([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)", "<a href=\"\\2\"target=\"_blank\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])((http(s?)://)(www\.)?([a-z0-9_-]+([a-z0-9_-]+)+)(/[^/ \n\r]*)*)", "<a href=\"\\2\"target=\"_blank\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])([a-z_-][a-z0-9\._-]*@[a-z0-9_-]+(\.[a-z0-9_-]+)+)","<a href=\"mailto:\\2\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])(www\.([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"http://\\2\" target=\"_blank\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])(www\.([a-z0-9_-]+([a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"http://\\2\" target=\"_blank\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])(ftp://([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"\\2\" target=\"_blank\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])(ftp://([a-z0-9_-]+([a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"\\2\" target=\"_blank\">\\2</a>",$string);
$string = eregi_replace("(^|[\n\r\t])(ftp\.([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"\\2\" target=\"_blank\">\\2</a>",$string);
// Quote
$string = preg_replace("#\[quote\](.+?)\[/quote\]#is","<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"3%\"> </td><td><small>Quote</small></td></tr><tr><td width=\"3%\"> </td><td style=\"border: 1px solid #232850;\"><table><tr><td>\\1</td></tr></table></td></tr></table>",$string);
$string = preg_replace("#\[quote=(.+?)\](.+?)\[/quote\]#is","<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"3%\"> </td><td><small>Quote: <b>\\1</b></small></td></tr><tr><td width=\"3%\"> </td><td style=\"border: 1px solid #232850;\"><table><tr><td>\\2</td></tr></table></td></tr></table>",$string);
// Plaatjes
$string = preg_replace("#\[img\](http)(.+?)\[/img\]#is","<img src=\"\\1\\2\" alt=\"Plaatje\" title\"Plaatje\" />",$string);
$string = preg_replace("#\[img\](.+?)\[/img\]#is","<img src=\"http://\\1\" alt=\"Plaatje\" title=\"Plaatje\" />",$string);
// Kleur
$string = preg_replace("#\[color=(.+?)\](.+?)\[/color\]#is","<font color=\"\\1\">\\2</font>",$string);
// Grootte
$string = preg_replace("#\[size=(.+?)\](.+?)\[/size\]#is","<font size=\"\\1\">\\2</font>",$string);
// Smileys
$string = str_replace(":)","<img src=\"images/smilies/smile.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("8|","<img src=\"images/smilies/huh.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":o","<img src=\"images/smilies/ohmy.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(";)","<img src=\"images/smilies/wink.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":P","<img src=\"images/smilies/tongue.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":D","<img src=\"images/smilies/biggrin.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("8)","<img src=\"images/smilies/cool.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("*-)","<img src=\"images/smilies/rolleyes.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":?","<img src=\"images/smilies/dry.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":@","<img src=\"images/smilies/mad.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":(","<img src=\"images/smilies/sad.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("8-)","<img src=\"images/smilies/unsure.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":|","<img src=\"images/smilies/blink.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("|:-|","<img src=\"images/smilies/ph34r.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":/","<img src=\"images/smilies/happy.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("|-)","<img src=\"images/smilies/sleep.gif\" alt=\"Smilie\" />",$string);
$string = str_replace("(l)","<img src=\"images/smilies/wub.gif\" alt=\"Smilie\" />",$string);
$string = str_replace(":s","<img src=\"images/smilies/wacko.gif\" alt=\"Smilie\" />",$string);
// Code
$string = preg_replace("_\[code\]([0-9])\[/code\]_ise", "self::phphighlite('\\1')", $string);
// Return
return $string;
}
?>
Dat is de UBB parser die ik gebruik, hij is gemaakt door Jorik.
Maar nu 1 probleem bij mij voegt hij \" toe alleen bij de eerste doet hij dat niet, en daardoor wordt alles na de 2de " rood..... En ik ben al heeel lang bezig met die UBB parsers maar het wil maar niet lukken weet iemand van jullie mijn fout?
Of kan iemand de ubb parser van phphulp posten, want volgens mij is die wel goed(A)
[edit]php tags vergeten:S, en er kwam een error in de ubb parser van phphulp, toch niet zo goed als ik dacht(A):P[/edit]
Gewijzigd op 01/01/1970 01:00:00 door Cyberboy fdsafds
stripslashes halen lost t denk ik wel op.
Even door Verder zal je vanzelf gewezen worden op het feit dat je alleen relevantie code mag plaatsen. Dit door het feit dat vrij weinig mensen 108 regels lang hun aandacht bij regular expressions en str_replaces kunnen houden.
Elwin
daar zit de fout waarschijnlijk ook niet in de 108 regels regexen, maar in de highligth function, maar ik post het graag compleet zodat jullie alles zien, en ik ga het nu proberen de stripslashes
Hij doet het, voor het door de highlighting functie halen doe ik stripslashes en vervolgens voeg ik ze weer toe! bedankt voor de tip
Marcel Boersma schreef op 11.12.2006 20:04:
Maar waarom alles posten als je wél weet in welk deel de fout zit? Wat hebben wij dan aan die irrelevante code?daar zit de fout waarschijnlijk ook niet in de 108 regels regexen, maar in de highligth function, maar ik post het graag compleet zodat jullie alles zien, en ik ga het nu proberen de stripslashes
Elwin