Código PHP:
function BBcode($texto){
$a = array(
"/\[i\](.*?)\[\/i\]/is",
"/\[b\](.*?)\[\/b\]/is",
"/\[u\](.*?)\[\/u\]/is"
);
$b = array(
"<i>$1</i>",
"<b>$1</b>",
"<u>$1</u>"
);
$texto = preg_replace($a, $b, $texto);
return $texto;
}
Código PHP:
function nuevo() {
$_POST['mensaje'] = nl2br($_POST['mensaje']);//tenemos en cuenta los saltos de línea
BBcode($_POST['mensaje']);
Código HTML:
[b]bbcode en negrita[/b] [i]bbcode en italica[/i] [u]bbcode subrallado[/u]