22-01-2009, 01:16 PM
j'ai un petit script pour mettre le BBcode sur sa messagerie, sa peut toujours interresser quelqu'un alors je le poste la.
Code PHP :
<?php
$contenue=str_replace("[b]", "<b>", "$contenue");
$contenue=str_replace("", "</b>", "$contenue");
$contenue=str_replace("[i]", "<i>", "$contenue");
$contenue=str_replace("", "</i>", "$contenue");
$contenue=str_replace("[u]", "<u>", "$contenue");
$contenue=str_replace("", "</u>", "$contenue");
$contenue=str_replace("[center]", "<center>", "$contenue");
$contenue=str_replace("", "</center>", "$contenue");
$contenue = preg_replace('/\[url=(.+?)\](.+?)\[\/url\]/', '<a href="$1" target="_blank">$2</a>', $contenue);
$contenue = preg_replace('/\[url](.+?)\[\/url\]/', '<a href="$1" target="_blank">$1</a>', $contenue);
$contenue=str_replace("[img]", "<img src='", "$contenue");
$contenue=str_replace("'/>", "'/>", "$contenue");
////////////////
// couleur
/////////////////
$contenue=str_replace("[color=red]", "<font color='red'>", "$contenue");
$contenue=str_replace("[color=green]", "<font color='green'>", "$contenue");
$contenue=str_replace("[/color]", "</font>", "$contenue");
////////////////
// couleur
/////////////////
$contenue = preg_replace('/\[color=#(.+?)\](.+?)\[\/color\]/', '<font color="$1">$2</font>', $contenue);
////////////////
//taille
/////////////////
$contenue=str_replace("[mini=7]", "<small>", "$contenue");
$contenue=str_replace("[/mini]", "</small>", "$contenue");
$contenue=str_replace("[size=9]", "<font size='1'>", "$contenue");
$contenue=str_replace("[size=12]", "<font size='2'>", "$contenue");
$contenue=str_replace("[size=18]", "<font size='4'>", "$contenue");
$contenue=str_replace("[size=24]", "<font size='6'>", "$contenue");
$contenue=str_replace("[/size]", "</font>", "$contenue");
////////////////
// smiley
/////////////////
$contenue=str_replace(":note:","<img src='images/smiley/icon1.gif'/>", "$contenue");
$contenue=str_replace(":fleche:","<img src='images/smiley/icon2.gif'/>", "$contenue");
$contenue=str_replace(":idee:","<img src='images/smiley/icon3.gif'/>", "$contenue");
$contenue=str_replace(":attention:","<img src='images/smiley/icon4.gif'/>", "$contenue");
$contenue=str_replace(":?:","<img src='image/smiley/icon5.gif'/>", "$contenue");
?>
y a aussi le formatage pour les smileys dedans
je précise que le script n'est pas de moi^^