Código PHP:
<?
function bbcode ($texto) {
$texto = eregi_replace("\\[url=([^\\[]*)\\]([^\\[]*)\\[/url\\]", "<a target=\"_blank\" href=\"\\1\">\\2</a>", $texto);
$texto = eregi_replace("\\[url\\]([^\\[]*)\\[/url\\]","<a target=\"_blank\" href=\"\\1\">\\1</a>",$texto);
$i=0;
while($i < 3) {
$texto = eregi_replace("\\[u\\]([^\\[]*)\\[/u\\]","<u>\\1</u>", $texto);
$texto = eregi_replace("\\[i\\]([^\\[]*)\\[/i\\]","<em>\\1</em>", $texto);
$texto = eregi_replace("\\[b\\]([^\\[]*)\\[/b\\]","<strong>\\1</strong>", $texto);
$texto = eregi_replace("\\[center\\]([^\\[]*)\\[/center\\]","<center>\\1</center>", $texto);
$texto = eregi_replace("\\[cita\\]([^\\[]*)\\[/cita\\]","\n<div class=\"css_title\">Cita\n<div class=\"css\">\\1</div></div>", $texto);
$i++;
}
return $texto;
}
function colorphp($s)
{
$s = str_replace("]\n", "]", $s);
$match = array('#\[php\](.*?)\[\/php\]#se');
$replace = array("'<div class=codigo><b>Codigo PHP:</b>'.highlight_string(stripslashes('$1'), true).'</div>'");
return preg_replace($match, $replace, $s);
}
?>
Código PHP:
<?
include('config.php');
include('bbcode.php');
$query = "select * from noticias where id='$id'";
$resp = mysql_query($query);
while ($datos = mysql_fetch_array($resp)) {
$fecha = date("d/m/Y",$datos[fecha]);
$muestra = bbcode(colorphp($datos[noticia]));
$extraido = bbcode($datos[origen]);
echo '
<table width=400>
<tr><td><b>'.$datos[titulo].'</b></td><td align="right"><b>'.$fecha.'</b></td></tr>
<tr><td colspan=2>'.$muestra.'</td></tr>
<tr><td><b>Origen: </b>'.$extraido.'</td><td align="right"><i>Enviada por <a href=perfil.php?id='.$datos[idautor].'><b>'.$datos[autor].'</b></a></i></td></tr>
</table><br>';
}
mysql_query($query);
?>
Un saludo