BBcode et forum

Répondre
Marshall31
le 04/11/2008 à 22:18
Marshall31
Bonjour à tous !

Voila jai pris le forum disponnible sur le site qui est trés bien fait mais j'ai un gros probleme avec les bbcode impossible de le faire marcher !

  1. $text = $data['message'];

  2. // on affiche le message
  3. echo nl2br(stripslashes(htmlentities(trim($text)))),'<p>&nbsp;</p>';
  4. echo '</td></tr>';

  5. function BBCode($Text) {

  6. // Replace any html brackets with HTML Entities to prevent executing HTML or script
  7. // Don't use strip_tags here because it breaks [url] search by replacing & with amp
  8. $Text = str_replace("<", "&lt;", $Text);
  9. $Text = str_replace(">", "&gt;", $Text);

  10. // Convert new line chars to html <br /> tags
  11. $Text = nl2br($Text);

  12. // Set up the parameters for a URL search string
  13. $URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
  14. // Set up the parameters for a MAIL search string
  15. $MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@";

  16. // Perform URL Search
  17. $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '<a href="$1" target="_blank">$1</a>', $Text);
  18. $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '<a href="$1" target="_blank">$2</a>', $Text);

  19. // Perform MAIL Search
  20. $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '<a href="mailto:$1">$1</a>', $Text);
  21. $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/", '<a href="mailto:$1">$2</a>', $Text);

  22. // Check for bold text
  23. $Text = preg_replace("(\[b\](.+?)\[\/b])is",'<span class="bold">$1</span>',$Text);

  24. // Check for Italics text
  25. $Text = preg_replace("(\[i\](.+?)\[\/i\])is",'<span class="italics">$1</span>',$Text);

  26. // Check for Underline text
  27. $Text = preg_replace("(\[u\](.+?)\[\/u\])is",'<span class="underline">$1</span>',$Text);

  28. // Check for strike-through text
  29. $Text = preg_replace("(\[s\](.+?)\[\/s\])is",'<span class="strikethrough">$1</span>',$Text);

  30. // Check for over-line text
  31. $Text = preg_replace("(\[o\](.+?)\[\/o\])is",'<span class="overline">$1</span>',$Text);

  32. // Check for colored text
  33. $Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","<span style=\"color: $1\">$2</span>",$Text);

  34. // Check for sized text
  35. $Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","<span style=\"font-size: $1px\">$2</span>",$Text);

  36. // Check for list text
  37. $Text = preg_replace("/\[list\](.+?)\[\/list\]/is", '<ul class="listbullet">$1</ul>' ,$Text);
  38. $Text = preg_replace("/\[list=1\](.+?)\[\/list\]/is", '<ul class="listdecimal">$1</ul>' ,$Text);
  39. $Text = preg_replace("/\[list=i\](.+?)\[\/list\]/s", '<ul class="listlowerroman">$1</ul>' ,$Text);
  40. $Text = preg_replace("/\[list=I\](.+?)\[\/list\]/s", '<ul class="listupperroman">$1</ul>' ,$Text);
  41. $Text = preg_replace("/\[list=a\](.+?)\[\/list\]/s", '<ul class="listloweralpha">$1</ul>' ,$Text);
  42. $Text = preg_replace("/\[list=A\](.+?)\[\/list\]/s", '<ul class="listupperalpha">$1</ul>' ,$Text);
  43. $Text = str_replace("[*]", "<li>", $Text);

  44. // Check for font change text
  45. $Text = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])","<span style=\"font-family: $1;\">$2</span>",$Text);

  46. // Declare the format for [code] layout
  47. $CodeLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
  48. <tr>
  49. <td class="quotecodeheader"> Code:</td>
  50. </tr>
  51. <tr>
  52. <td class="codebody">$1</td>
  53. </tr>
  54. </table>';
  55. // Check for [code] text
  56. $Text = preg_replace("/\[code\](.+?)\[\/code\]/is","$CodeLayout", $Text);

  57. // Declare the format for [quote] layout
  58. $QuoteLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
  59. <tr>
  60. <td class="quotecodeheader"> Quote:</td>
  61. </tr>
  62. <tr>
  63. <td class="quotebody">$1</td>
  64. </tr>
  65. </table>';

  66. // Check for [code] text
  67. $Text = preg_replace("/\[quote\](.+?)\[\/quote\]/is","$QuoteLayout", $Text);

  68. // Images
  69. // [img]pathtoimage[/img]
  70. $Text = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="$1">', $Text);

  71. // [img=widthxheight]image source[/img]
  72. $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '<img src="$3" height="$2" width="$1">', $Text);

  73. return $Text;
  74. }
  75. $text = BBCode($text);

  76. [/code]
[url]www.pageorank.com[/url]
Marshall31
le 04/11/2008 à 22:20
Marshall31
oups petite erreur

  1. $message = BBCode($message);


et
  1. $message = $data['message'];

  2. // on affiche le message
  3. echo nl2br(stripslashes(htmlentities(trim($message)))),'<p>&nbsp;</p>';
  4. echo '</td></tr>';

  5. function BBCode($Text) {
[url]www.pageorank.com[/url]
LA GLOBULE
le 04/11/2008 à 22:33
LA GLOBULE
Et quel est le problème ? Tu as des erreurs ? Des changements de texte qui ne se font pas ?
Marshall31
le 04/11/2008 à 22:57
Marshall31
Ben le probleme est que les 2 premier message s'affiche et le reste du site est couper en deux !
[url]www.pageorank.com[/url]
LA GLOBULE
le 04/11/2008 à 23:44
LA GLOBULE
Oué, mais la, tu fais 15 000 expression régulières.
Tu as essayé un peu d'isoler ton problème pour voir quelle regex fuckait ton HTML ?

D'autre part, as tu testé ton script sur une "page vierge" pour voir si ce n'était pas ton montage HTML qui avait un soucis ?
Répondre

Ecrire un message

Votre message vient d'être créé avec succès.
LoadingChargement en cours