bonjour voila jai un petit probleme avec les bbcode sa me les affiche pour sa y a pas de probleme le seul soucis c'est qu'ils ne se mette pas sur la meme ligne sa saute une ligne a chaque fois je comprend pas trop pourquoi.
quelqu'un peu m'aider svp
Version imprimable
bonjour voila jai un petit probleme avec les bbcode sa me les affiche pour sa y a pas de probleme le seul soucis c'est qu'ils ne se mette pas sur la meme ligne sa saute une ligne a chaque fois je comprend pas trop pourquoi.
quelqu'un peu m'aider svp
Bonjour,
Peut-être que si tu expliquais le contexte on serait plus à même de te fournir de l'aide ?
Voir mettre un peu de ton code :)
oupss desoler jai oublier de mettre les sources
le probleme c'est quelle est super longue
j'annonce elle est pas de moi je lais juste modifier
le probleme est que quand je met [ b ][ /b ] et [ i ] [ /i ] sa me les et comme sa :
[b ][ /b]
[i ][ /i]
je sais pas si je mexplique bien
Code:
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317<?php class parse_bbcode { // variable phpmethod : "string" for colour php code, // "page" to colour and show it in a table with number of line var $phpmethod; // Constructor (nothing to load) function parse_bbcode($phpmethod = "page") { $this->phpmethod = $phpmethod; return true; } /** * function parse * * @param string : the string to transform * @param Array of string : list of tokens **/ function parse($text, $methods = "all", $striptags = true) { $text = str_replace("<?php", "<<<@!1!@>>>", $text); $ret_val = $striptags ? $this->html($text) : $text; if (is_array($methods)) { foreach ($methods AS $method) { if (method_exists($this, "_$method")) { $ret_val = $this->{"_$method"}($ret_val); } } } elseif($methods == "all") { foreach(get_class_methods($this) AS $method) { $pattern = '/^_.*$/'; if (preg_match($pattern, $method)) { $ret_val = $this->{$method}($ret_val); } } } else { $ret_val = false; } $ret_val = str_replace("\\'","'", $ret_val); $ret_val = str_replace("\\\"","\"", $ret_val); $ret_val = $striptags ? $this->nltobr($ret_val) : $ret_val; return $ret_val; } // parse a file function parsefile($file, $methods = "all", $striptags = true) { if (!file_exists($file)) { return false; } return $this->parse(implode('', file($file)), $methods, $striptags); } ### privates functions ### //******************************************************************* // html function: colour html tags. function html($text) { $In = array( '`<(/?[^ &<]+ *)>`', '`([^ =]+)="(.*?)"`', '`<([^< ]+)`', '`<([^&]+?)>`' , '`(?<=[[:space:]])[[:space:]]`' ); $Out = array( '<span class="html"><$1></span>', '<span class="attribut">$1="</span><span class="value">$2</span><span class="attribut">"</span>', '<$1', '<span class="html"><$1></span>', '  ' ); $text = preg_replace($In, $Out, nl2br(htmlentities($text, ENT_NOQUOTES))); RETURN $text; } // \n to <br /> tag function nltobr($text) { RETURN $text; } /* * elementary functions */ // les smileys function _smiley1($text) { return str_replace(':)', '<img src="./images/smiley/smile.png" alt="" style="border:0"/>', $text); } function _smiley2($text) { return str_replace(':D', '<img src="./images/smiley/heureux.png" alt="" style="border:0"/>', $text); } function _smiley3($text) { return str_replace(';)', '<img src="./images/smiley/clin" alt="" style="border:0"/>', $text); } function _smiley4($text) { return str_replace(':p', '<img src="./images/smiley/langue.png" alt="" style="border:0"/>', $text); } function _smiley5($text) { return str_replace(':lol:', '<img src="./images/smiley/rire.gif" alt="" style="border:0"/>', $text); } function _smiley6($text) { return str_replace(':euh:', '<img src="./images/smiley/unsure.gif" alt="" style="border:0"/>', $text); } function _smiley7($text) { return str_replace(':(', '<img src="./images/smiley/triste.png" alt="" style="border:0"/>', $text); } function _smiley8($text) { return str_replace(':o', '<img src="./images/smiley/huh.png" alt="" style="border:0"/>', $text); } function _smiley9($text) { return str_replace(':colere2:', '<img src="./images/smiley/mechant.png" alt="" style="border:0"/>', $text); } function _smiley10($text) { return str_replace('o_O', '<img src="./images/smiley/blink.gif" alt="" style="border:0"/>', $text); } function _smiley11($text) { return str_replace('^^°', '<img src="./images/smiley/hihi.png" alt="" style="border:0"/>', $text); } function _smiley12($text) { return str_replace(':-°', '<img src="./images/smiley/siffle.png" alt="" style="border:0"/>', $text); } //fin smiley // email bbcode bob@bob.net function _email($text) { return preg_replace("#\[email\](.*?)\[/email\]#si", "<a href=\"mailto:\\1\">\\1</a>", $text); } // bold bbcode bold function _bold($text) { return preg_replace("#\[b\](.*?)\[/b\]#", "<div class='gras'>\\1</div>", $text); } // italic bbcode italic function _italique($text) { return preg_replace("#\[i\](.*?)\[/i\]#si", "<div class='italique'>\\1</div>", $text); } // Underline bbcode underline function _underline($text) { return preg_replace("#\[u\](.*?)\[/u\]#si", "<div class='souligne'>\\1</div>", $text); } // Underline bbcode [h1]h1[/h1] function _h1($text) { return preg_replace("#\[h1\](.*?)\[/h1\]#si", "<h1>\\1</h1>", $text); } // Underline bbcode [h2]h2[/h2] function _h2($text) { return preg_replace("#\[h2\](.*?)\[/h2\]#si", "<h2>\\1</h2>", $text); } // link maker bbcode google function _url($text) { $remplacement = '<a href="http://\1" target="_blank">\2</a>'; return preg_replace("#\[url=(.*?)\](.*?)\[/url\]#si", $remplacement, $text); } // image bbcode [img]my_image.gif[/img] function _img($text) { return preg_replace("#\[img\](.*?)\[/img\]#si", "<img src=\"\\1\" border=\"none\" />", $text); } // br bbcode function _br($text) { $pattern = '|\[br]|Ui'; return preg_replace($pattern, '<br />', $text); } // center bbcode function _center($text) { RETURN $text = preg_replace("#\[center\](.*?)\[/center\]#si","<div align=\"center\">\\1</div>",$text); } // center bbcode function _gauche($text) { RETURN $text = preg_replace("#\[gauche\](.*?)\[/gauche\]#si","<div align=\"left\">\\1</div>",$text); } // center bbcode function _droite($text) { RETURN $text = preg_replace("#\[droite\](.*?)\[/droite\]#si","<div align=\"right\">\\1</div>",$text); } // center bbcode function _justifie($text) { RETURN $text = preg_replace("#\[justifie\](.*?)\[/justifie\]#si","<div align=\"justify\">\\1</div>",$text); } // citation bbcode function _quote($text) { $text = preg_replace("|\[quote\]|Ui","<blockquote>\\1",$text); $text = preg_replace("|\[quote=[\"']?([^\"']+)[\"']?\]|Ui","<blockquote>\\1 a dit:<br />",$text); $text = preg_replace("|\[/quote\]|Ui","</blockquote>",$text); RETURN $text; } // hr bbcode function _hr($text) { RETURN preg_replace("|\[hr\]|Ui","<hr noshade size=1 />",$text); } // font bbcode function _font($text) { $text = preg_replace("|\[font=([a-z]+)\]|Ui","<span style=\"color: \\1\">",$text); $text = preg_replace("§\[/(font|size|color)\]§Ui","</span>",$text); $text = preg_replace("§\[size=([1-4][0-9]|[89])\]§Ui","<span style=\"font-size: \\1pt\">",$text); $text = preg_replace("§\[color=(#[0-9A-F]{6}|[a-z]+)\]§Ui","<span style=\"color: \\1\">",$text); RETURN $text; } // this function appeal the "phpmethod" function function _php($text) { if($this->phpmethod == "string") { RETURN $this->stringphp($text); } elseif($this->phpmethod == "page") { RETURN $this->pagephp($text); } else { RETURN $text; } } /** PHPbbcodes functions **/ // php highlighter bbcode <<<@!2!@>>> function stringphp($text) { $strip_php_tags = ereg('<\?php.+\?>', $text) ? false : true; if(preg_match_all("#\[php\](.+?)\[/php\]#si", $text, $match)) { for($i = 0; $i <= count($match[0]); $i++) { $match2 = str_replace('<<<@!3!@>>>', ($strip_php_tags ? '?>' : ''), $match2); ob_start(); highlight_string($match2); $match2 = ob_get_contents(); ob_end_clean(); $text = str_replace($match[0][$i], $match2, $text); $text = $strip_php_tags ? preg_replace('<font *color="#[0-9A-F]{6}"> *(<\?|\?>) *</font>', '', $text) : $text; } } return $text; } // function pagephp to show the php code colored in a table with number of line function pagephp($text) { if(preg_match_all("#\[php\](.+?)\[/php\]#si", $text, $match)) { for($i = 0; $i < count($match[0]); $i++) { $match2 = str_replace("<<<@!4!@>>>", "?>", $match2); $match2 = str_replace("<","<", $match2); $match2 = str_replace (">", ">", $match2); ob_start(); highlight_string($match2); $code = ob_get_contents(); ob_end_clean(); $code = preg_replace("<br />", "<br>", $code); $code = preg_replace("\r</font>", "</font>\r", $code); $code = str_replace("\n","",$code); $code = str_replace("<code>", "", $code); $code = str_replace("</code>", "", $code); $code = explode("<br>", $code); $newcode = "<table style=\"width: 95%\"><tr><td>"; for($j = 0; $j < count($code); $j++) { if($j % 2) $class_id = "couleur3"; else $class_id = "couleur4"; $newcode.= "<span class=\"".$class_id."\" style=\"width: 100%\"onmouseout=\"change_couleur2(this)\" onmouseover=\"change_couleur2(this)\"><span style=\"color: white\"><b>".($j+1)."</b></span>  ".$code[$j]."</span>"; } $newcode .= "</td></tr></table>"; $text = str_replace($match[0][$i],$newcode,$text); } } RETURN "$text"; } function _classcolourhtml($text) { return preg_replace("#\[html\](.*?)\[/html\]#si", "<span class=\"html\">\\1</span>", $text); } } ?>
Salut
Ce que tu évoque c'est soit au moment de la saisie du code BBCode, soit au moment de l'enregistrement de ce contenu BBCode.Citation:
le probleme est que quand je met [ b ][ /b ] et [ i ] [ /i ] sa me les et comme sa :
[b ][ /b]
[i ][ /i]
Or, la classe que tu as mis me semble essentiellement fait pour convertir le code BBCode en code HTML.
Ton problème ne se situerait pas à ce niveau, sauf erreur.
Faudrait peut être voir comment est généré ce code BBCode, quel éditeur.
(Si c'est une usine à gaz, ça risque d'être compliqué)
Ou alors au moment de l'enregistrement.
As tu essayé de voir (genre faire un echo ou print_r) ce que contient tout le contenu (cette chaine BBCode) juste avant enregistrement, s'il contient des sauts de lignes non désirés ou pas ?
enfaite jai trouver l'erreur est a cause des <div class=""> a la ligne 141 146 et 151.
voila merci en tout cas pour votre aide sa ma mis sur la voie
Donc ce que tu obtenais n'était pas [b ][ /b] mais <div></div> (du HTML), ce qui provoquait des retours à la ligne.Citation:
enfaite jai trouver l'erreur est a cause des <div class=""> a la ligne 141 146 et 151.
Tu as dû remplacé les div par des span (théoriquement).
J'avais pas fais attention non plus.