function bbCode($t) {
   $t=str_replace("[/]", "<hr width=\"100%\" size=\"1\" />", $t);
   $t=str_replace("[hr]", "<hr width=\"100%\" size=\"1\" />", $t);
   
   $t=str_replace("[b]", "<strong>", $t);
   $t=str_replace("[/b]", "</strong>", $t);
   
   $t=str_replace("[i]", "<em>", $t);
   $t=str_replace("[/i]", "</em>", $t);
   
   $t=str_replace("[u]", "<u>", $t);
   $t=str_replace("[/u]", "</u>", $t);
   
   $t=str_replace("[center]", "<div style=\"text-align: center\">", $t);
   $t=str_replace("[/center]", "</div>", $t);
   
   $t=str_replace("[right]", "<div style=\"text-align: right\">", $t);
   $t=str_replace("[/right]", "</div>", $t);
   
   $t=str_replace("[justify]", "<div style=\"text-align: justify\">", $t);
   $t=str_replace("[/justify]", "</div>", $t);
   
   $t=str_replace("[/color]", "</span>", $t);
   $regCouleur="\[color= ?(([[:alpha:]]+)|(#[[:digit:][:alpha:]]{6})) ?\]";
   $t=ereg_replace($regCouleur, "<span style=\"color: \\1\">", $t);
   
   $t=str_replace("[/size]", "</span>", $t);
   $regCouleur="\[size= ?([[:digit:]]+) ?\]";
   $t=ereg_replace($regCouleur, "<span style=\"font-size: \\1px\">", $t);
   
   $regLienSimple="\[url\] ?([^\[]*) ?\[/url\]";
   $regLienEtendu="\[url ?=([^\[]*) ?] ?([^]]*) ?\[/url\]";
   if (ereg($regLienSimple, $t)) $t=ereg_replace($regLienSimple, "<a href=\"\\1\">\\1</a>", $t);
   else $t=ereg_replace($regLienEtendu, "<a href=\"\\1\" target=\"_blank\">\\2</a>", $t);
   
   $regMailSimple="\[email\] ?([^\[]*) ?\[/email\]";
   $regMailEtendu="\[email ?=([^\[]*) ?] ?([^]]*) ?\[/email\]";
   if (ereg($regMailSimple, $t)) $t=ereg_replace($regMailSimple, "<a href=\"mailto:\\1\">\\1</a>", $t);
   else $t=ereg_replace($regMailEtendu, "<a href=\"mailto:\\1\">\\2</a>", $t);
   
   $regImage="\[img\] ?([^\[]*) ?\[/img\]";
   $regImageAlternatif="\[img ?= ?([^\[]*) ?\]";
   if (ereg($regImage, $t)) $t=ereg_replace($regImage, "<img src=\"\\1\" alt=\"\" border=\"0\" />", $t);
   else $t=ereg_replace($regImageAlternatif, "<img src=\"\\1\" alt=\"\" border=\"0\" />", $t);
   
   return $t;
}
Published in: PHP
Download

Related snippets