Ik ben aan het proberen met het maken van een bb parser voor m'n site, omdat die wie ik nu heb te sloom is (0.045 per parse)
Maar nu ben ik bij het punt van de code tag om de smilies en bb codes er niet in te laten vervangen. Volgens mij hoort het gene wat ik nu heb te werken, maar dat doet het dus niet
hopelijk weten jullie wat ik fout doe...
Maar nu ben ik bij het punt van de code tag om de smilies en bb codes er niet in te laten vervangen. Volgens mij hoort het gene wat ik nu heb te werken, maar dat doet het dus niet
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
| <? class ubb { var $smilie_find = array( '>:)', ':)', '|:(', ":'(", ':P', ); var $smilie_replace = array( '[img]"../pics/smilies/devil.gif">', '<img[/img]', '[img]"../pics/smilies/frusty.gif">', '<img[/img]', '[img]"../pics/smilies/puh2.gif"[/img]', ); function code($input, $numbers, $code) { $input = trim($input); for($i=0; $i < count($this->smilie_find); $i++) { $input = str_replace($this->smilie_replace["$i"], $this->smilie_find["$i"], $input); //echo $this->smilie_replace["$i"] . " ---- " . $this->smilie_find["$i"] . "<br>\n"; } if($code == 0) $output = $input; elseif($code == 1) { $input = str_replace("<", "<", $input); $input = str_replace(">", ">", $input); $input = str_replace(""", '"', $input); $input = str_replace("&", "&", $input); ob_start(); @highlight_string($input); $output = ob_get_contents(); ob_end_clean(); } $output = str_replace("]", "]", $output); $output = str_replace("[", "[", $output); return $output; } function bbcode($input) { $input = nl2br(htmlspecialchars(trim($input))); for($i=0; $i < count($this->smilie_find); $i++) $input = str_replace($this->smilie_find["$i"], $this->smilie_replace["$i"], $input); $input = preg_replace('!\\[code\](.+)\\[/code\]!', "Script:<hr>" . $this->code("\\1", 1, 1) . "<hr>", $input); $input = preg_replace('!\\[php\](.+)\\[/php\]!', $this->code("\\1", 1, 1), $input); $input = preg_replace('!\\[no\](.+)\\[/no\]!', $this->code("\\1", 0, 0), $input); $input = preg_replace('!\\[b\](.+)\\[/b\]!', "<b>\\1</b>", $input); $input = preg_replace('!\\[u\](.+)\\[/u\]!', "<u>\\1</u>", $input); $input = preg_replace('!\\[i\](.+)\\[/i\]!', "<i>\\1</i>", $input); $input = preg_replace('!\\[s\](.+)\\[/s\]!', "<s>\\1</s>", $input); $input = preg_replace('!\\[li\](.+)\\[/li\]!', "<li>\\1</li>", $input); $input = preg_replace('!\\[quote\](.+)\\[/quote\]!', "<blockquote>Quote:<hr>\\1</hr></blockquote>", $input); $input = preg_replace('!\[quote=(.+)\](.+)\\[/quote\]!', "<blockquote>Quote van \\1<hr>\\2</blockquote>", $input); $input = preg_replace('!\\[url\](.+)\\[/url\]!', "<a href=\"\\1\">\\1</a>", $input); $input = preg_replace('!\[url=(.+)\](.+)\\[/url\]!', "<a href=\"\\1\">\\2</a>", $input); $input = preg_replace('!\[img=(.+)\](.+)\]!', "[img]\"\\1\"[/img]", $input); return $input; } } $bb = new ubb; echo $bb->bbcode($_POST["bericht"]); ?> <!-- ff een formpje om te testen :) --> <form name="form1" method="post" action=""> <p> <textarea name="bericht" cols="80" rows="8" id="bericht"><? echo htmlspecialchars($_POST["bericht"]); ?></textarea> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> |
hopelijk weten jullie wat ik fout doe...
[ Voor 22% gewijzigd door Verwijderd op 10-01-2003 12:56 ]