romain Rang: Administrateur
Nombre de messages : 346 Date d'inscription : 01/08/2004
| Sujet: bbcode Jeu 16 Mar à 0:57 | |
| voici une fonction de bbcode : - Code:
-
function bbcode($text) { $text = nl2br(addslashes($text)); $text = str_replace("[b]", "<b>", $text); $text = str_replace("[/b]", "</b>", $text);
$text = str_replace("[u]", "<u>", $text); $text = str_replace("[/u]", "</u>", $text);
$text = str_replace("[i]", "<i>", $text); $text = str_replace("[/i]", "</i>", $text); $text = str_replace("[center]", "<center>", $text); $text = str_replace("[/center]", "</center>", $text); $text = str_replace(" ", " ", $text); $text = str_replace(':)','<img src="http://www.mapping-area.com/images/smiley/smile.gif" alt="" style="border:0"/>',$text); $text = str_replace(';)','<img src="http://www.mapping-area.com/images/smiley/hehe.gif" alt="" style="border:0"/>',$text); $text = str_replace(':P','<img src="http://www.mapping-area.com/images/smiley/langue.gif" alt="" style="border:0"/>',$text); $text = str_replace(':D','<img src="http://www.mapping-area.com/images/smiley/bigrin.gif" alt="" style="border:0"/>',$text); $text = str_replace(':o','<img src="http://www.mapping-area.com/images/smiley/bouh.gif" alt="" style="border:0"/>',$text); $text = str_replace('lol','<img src="http://loka.forumactif.com/images/smiles/lol!.gif" alt="" style="border:0"/>',$text); $text = str_replace('boulet!','<img src="http://loka.forumactif.com/images/smiles/boulet.gif" alt="" style="border:0"/>',$text); $text = str_replace(':\'(','<img src="http://loka.forumactif.com/images/smiles/icon_sad.gif" alt="" style="border:0"/>',$text); $text = str_replace(':evil:','<img src="http://sitebas.free.fr/forum/images/smiles/icon_evil.gif" alt="" style="border:0"/>',$text);
$patterns = array(); $replacements = array();
$patterns[] = "#\[img\](.*?)\[/img\]#si"; $replacements[] = "<img src=\"\\1\" border=\"0\" />";
$patterns[] = "#\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]#is"; $replacements[] = "<a href=\"\1\2\" target=\"_blank\" class=\"postlink\">\1\2</a>";
$patterns[] = "#\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]#si"; $replacements[] = "<a href=\"http://\\1\" target=\"_blank\" class=\"postlink\">\\1</a>";
$patterns[] = "#\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]#si"; $replacements[] = "<a href=\"\\1\\2\">\\6</a>";
$patterns[] = "#\[url=(([\w\-]+\.)*?[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\](.*?)\[/url\]#si"; $replacements[] = "<a href=\"http://\\1\">\\5</a>";
$patterns[] = "#\[email\]([a-z0-9\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si"; $replacements[] = "<a href=\"mailto:\\1\">\\1</A>"; return preg_replace($patterns, $replacements, $text); } et la fonction | |
|