La mayoria de las webs de ayuda para webmasters contienen artículos en los cuales expresan un sin fin de códigos para que puedas ocuparlos. Pero la mayoria de estos son monótonos por la forma de representarlos, para no estar en esa lista te enseñaremos la forma de como colorear el código php.
function ColoreaCodigo($texto) {
$texto = str_replace("
", "", $texto);
$texto = str_replace("
", "", $texto);
$texto = str_replace(">", ">", $texto);
$texto = str_replace("<", "<", $texto);
$texto = str_replace("&", "&", $texto);
$texto = str_replace('$', '\$', $texto);
$texto = str_replace('n', '\n', $texto);
$texto = str_replace('r', '\r', $texto);
$texto = str_replace('t', '\t', $texto);
$texto = str_replace('"', '"', $texto);
$texto = stripslashes($texto);
ob_start();
$nivelviejo=error_reporting(0);
highlight_string($texto);
error_reporting($nivelviejo);
$buffer = ob_get_contents();
ob_end_clean();
if ($variable) {
$abrirpost = strpos($buffer,'<?');
$cerrarpost = strrpos($buffer, '?');
$buffer=substr($buffer, 0, $abrirpost).substr($buffer, $abrirpost+5, $cerrarpost-($abrirpost+5)).substr($buffer, $cerrarpost+5);
}
$buffer=str_replace("","",$buffer);
$buffer=str_replace("","",$buffer);
return $buffer;
}
?>
Con esta funcion basta y sobra. Recuerda que al momento de querer colorear el codigo es importante poner las etiquetas y ?> o si no no te va a funcionar.
Espero les sirva de algo.
Salu2!
Autor: aBsTrAcTo
http://foro.el-hacker.com/index.php/topic,15266.0.html
Usuarios que han visto este tema también han visto...
- Redondear decimales en PHP
- Resaltar Palabra Buscada con PHP
- Editar y Borrar datos en MySQL con PHP
- Array en formulario de PHP
- Comprobar si un usuario es válido con Ajax y PHP
- Versión imprimible de este documento
- Enviar por e-mail este documento