bon en fait je me suis inspiré du bbcode:
function bbcode_lien2($url) {
if ( preg_match('`^http://`', $url[1]) ) {
return '<a href="'.$url[1].'">'.$url[2].'</a>';
}
else {
return '<a href="
http://'. $url[1] .'">'. $url[2] .'</a>';
}
}
function bbcode_code($code) {
return $code[1];
}
function bbcode_com($com) {
return "<em>//".$com[1]."</em>";
}
function bbcode_paragraphe($para) {
return "<p>".$para[1]."</p>";
}
function creer_bbcode ($string) {
$string = htmlentities ($string);
$string = nl2br($string);
$string = preg_replace_callback("/\[lien=(.*?)\](.*?)\[\/lien\]/is",'bbcode_lien2', $string);
$string = preg_replace_callback("/\[lien\](.*?)\[\/lien\]/is",'bbcode_lien', $string);
$string = preg_replace_callback("/\[code\](.*?)\[\/code\]/is",'bbcode_code', $string);
$string = preg_replace_callback("/\[com\](.*?)\[\/com\]/is",'bbcode_com', $string);
$string = preg_replace_callback("/\[p\](.*?)\[\/p\]/is",'bbcode_paragraphe', $string);
$string = preg_replace("(\[b\](.+?)\[\/b])is",'<strong>$1</strong>', $string);
return ($string);
}
et maintenant ca marche, quand j'ai besoin de traiter ma variable, je fais simplement:
echo creer_bbcode($variable);