Una función que ojala le sirva a mas de 1 .. no se si estaba pero la hice recién y pensé en compartirla... si pueden mejorarla de ahí y volver a postearla seria bueno para que fuera mas profesional .. :B
saludos!
Código php:
Ver originalclass StringFunctions {
/**
* bbcode2html() Estandard bbcode transform [http://www.bbcode.org/reference.php]
*
* @access public
* @param $cadena string BBCODE
* @return $cadena string HTML
*/
public function bbcode2html($cadena) {
// Style's to box code, spoiler, etc.
define ( 'TITLE_DATA', ' style="font-size:11px;color:#666;"' ); define ( 'BOX_STYLE', ' style="border:1px solid #ccc;background:#f1f1f1;padding:5px;margin:2px;"' );
// Array bbcode & html PRCE
$bbcode [] = '/\[b\](.*)\[\/b\]/is';
$html [] = '<b>$1</b>';
$bbcode [] = '/\[u\](.*)\[\/u\]/is';
$html [] = '<u>$1</u>';
$bbcode [] = '/\[i\](.*)\[\/i\]/is';
$html [] = '<i>$1</i>';
$bbcode [] = '/\[s\](.*)\[\/s\]/is';
$html [] = '<s>$1</s>';
$bbcode [] = '/\[br\]/iU';
$html [] = '<br />';
$bbcode [] = '/\[font=(?:"|\')?([\w\s-]*)(?:"|\')?\](.*)\[\/font\]/is';
$html [] = '<span style="font-family:$1;">$2</span>';
$bbcode [] = '/\[size=(?:"|\')?([\w\s-]*)(?:"|\')?\](.*)\[\/size\]/is';
$html [] = '<span style="font-size:$1px;">$2</span>';
$bbcode [] = '/\[url\](.*)\[\/url\]/i';
$html [] = '<a href="$1">$1</a>';
$bbcode [] = '/\[url=(?:"|\')?(.*)(?:"|\')?\](.*)\[\/url\]/i';
$html [] = '<a href="$1">$2</a>';
$bbcode [] = '/\[quote\]/i';
$html [] = '<div' . TITLE_DATA . '>Cita:</div><blockquote' . BOX_STYLE . '>';
$bbcode [] = '/\[quote=(?:"|\')?([\w\s-]*)(?:"|\')?\]/is';
$html [] = '<div' . TITLE_DATA . '><b>$1</b> escribió:</div><blockquote' . BOX_STYLE . '>';
$bbcode [] = '/\[\/quote\]/i';
$html [] = '</blockquote>';
$bbcode [] = '/\[color=(?:"|\')?(.*)(?:"|\')?\](.*)\[\/color\]/i';
$html [] = '<font color="$1">$2</font>';
$bbcode [] = '/\[img\](.*)\[\/img\]/i';
$html [] = '<img src="$1" />';
$bbcode [] = '/\[email\](.*)\[\/email\]/i';
$html [] = '<a href="mailto:$1">$1</a>';
$bbcode [] = '/\[email=(?:"|\')?(.*)(?:"|\')?\](.*)\[\/email\]/i';
$html [] = '<a href="mailto:$1">$2</a>';
$bbcode [] = '/\[list\](.*)\[\/list\]/is';
$html [] = '<ul>$1</ul>';
$bbcode [] = '/\[list=1\](.*)\[\/list\]/is';
$html [] = '<ol style="list-style-type:decimal">$1</ol>';
$bbcode [] = '/\[list=a\](.*)\[\/list\]/is';
$html [] = '<ol style="list-style-type:lower-alpha">$1</ol>';
$bbcode [] = '/\[\*\](.*)/iU';
$html [] = '<li>$1 ';
$bbcode [] = '/\[code\](.*)\[\/code\]/ise';
$html [] = "'<div'.TITLE_DATA.'>Codigo:</div><div'.BOX_STYLE.'>'.highlight_string(trim(stripslashes('$1')),true).'</div>'";
$bbcode [] = '/\[align=(?:"|\')?(left|center|right){1}(?:"|\')?\](.*)\[\/align\]/is';
$html [] = '<div style="text-align:$1;">$2</div>';
return $cadena;
}
}