par
Ultim4T0m » 29 janv. 2007, 01:39
Pourquoi des crochets ?
Là où tu affiches le texte, stocké dans la variable $contenu, je pense que tu fais
echo $contenu;
Avec la fonction que tu nous a montré, qui converti le BBCode en html, tu peux faire comme ça :
Fichier bbcode.php -
function bbcode($text) {
$text = preg_replace("#\[img\]((ht|f)tp://)([^\r\n\t<"]*?)\[/img\]#sie", "'<img src=\\1' . str_replace(' ', '%20', '\\3') . '>'", $text);
$text = preg_replace("#\[url\]((ht|f)tp://)([^\r\n\t<"]*?)\[/url\]#sie", "'<a href="\\1' . str_replace(' ', '%20', '\\3') . '" target=blank>\\1\\3</a>'", $text);
$text = preg_replace("/\[url=(.+?)\](.+?)\[\/url\]/", "<a href=$1 target=blank>$2</a>", $text);
$text = preg_replace("/\[b\](.+?)\[\/b\]/", "<b>$1</b>", $text);
$text = preg_replace("/\[i\](.+?)\[\/i\]/", "<i>$1</i>", $text);
$text = preg_replace("/\[u\](.+?)\[\/u\]/", "<u>$1</u>", $text);
$text = preg_replace("/\[code\](.+?)\[\/code\]/", "<table width=100%><tr><th align=left>Code :</th></tr><tr><td align=left><code>$1</code></td></tr></table>", $text);
$text = preg_replace("/\[quote\](.+?)\[\/quote\]/", "<table width=100%><tr><th align=left>citation :</th></tr><tr><td align=left>$1</td></tr></table>", $text);
$text = preg_replace("/\[quote=(.+?)\](.+?)\[\/quote\]/", "<table width=100%><tr><th align=left>$1 :</th></tr><tr><td align=left>$2</td></tr></table>", $text);
$text = preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/", "<font color=$1>$2</font>", $text);
return $text;
}
Fichier principal -
include 'bbcode.php'; // On inclue la fonction pour le BBCode
echo bbcode($contenu);
Mais en voyant ca echobbcode[$contenu] je n'ai qu'un conseil...
www.phpdebutant.org
Pourquoi des crochets ?
Là où tu affiches le texte, stocké dans la variable $contenu, je pense que tu fais
[php]echo $contenu;[/php]
Avec la fonction que tu nous a montré, qui converti le BBCode en html, tu peux faire comme ça :
Fichier bbcode.php -
[php]
function bbcode($text) {
$text = preg_replace("#\[img\]((ht|f)tp://)([^\r\n\t<"]*?)\[/img\]#sie", "'<img src=\\1' . str_replace(' ', '%20', '\\3') . '>'", $text);
$text = preg_replace("#\[url\]((ht|f)tp://)([^\r\n\t<"]*?)\[/url\]#sie", "'<a href="\\1' . str_replace(' ', '%20', '\\3') . '" target=blank>\\1\\3</a>'", $text);
$text = preg_replace("/\[url=(.+?)\](.+?)\[\/url\]/", "<a href=$1 target=blank>$2</a>", $text);
$text = preg_replace("/\[b\](.+?)\[\/b\]/", "<b>$1</b>", $text);
$text = preg_replace("/\[i\](.+?)\[\/i\]/", "<i>$1</i>", $text);
$text = preg_replace("/\[u\](.+?)\[\/u\]/", "<u>$1</u>", $text);
$text = preg_replace("/\[code\](.+?)\[\/code\]/", "<table width=100%><tr><th align=left>Code :</th></tr><tr><td align=left><code>$1</code></td></tr></table>", $text);
$text = preg_replace("/\[quote\](.+?)\[\/quote\]/", "<table width=100%><tr><th align=left>citation :</th></tr><tr><td align=left>$1</td></tr></table>", $text);
$text = preg_replace("/\[quote=(.+?)\](.+?)\[\/quote\]/", "<table width=100%><tr><th align=left>$1 :</th></tr><tr><td align=left>$2</td></tr></table>", $text);
$text = preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/", "<font color=$1>$2</font>", $text);
return $text;
}[/php]
Fichier principal -
[php]
include 'bbcode.php'; // On inclue la fonction pour le BBCode
echo bbcode($contenu);
[/php]
Mais en voyant ca echobbcode[$contenu] je n'ai qu'un conseil... www.phpdebutant.org