fiz um sistema para colorir o código PHP que ficar entre a tag
Vejam:
codephp.php
<?php
# ------------------------------------------
# Produzido por: Felipe Nascimento
# (Justice) Deus seja louvado!
# ------------------------------------------
include("form.php");
function verifTag($txt)
{
//quantidade de tags iniciais e finais
$nQuantTagInicial = substr_count($txt, "[php]");
$nQuantTagFinal = substr_count($txt, "[/php]");
if ($nQuantTagInicial == $nQuantTagFinal)
{
for ($i=0; $i<$nQuantTagInicial; $i++)
{
$aPosInicial[] = $posi = strpos($txt, "[php]");
$aPosFinal[] = $posf = strpos($txt, "[/php]");
for ($j=0; $j<strlen("[/php]"); $j++)
{
$txt[$posi+$j] = "";
$txt[$posf+$j] = "";
}
}
for ($i=0; $i<$nQuantTagInicial-1; $i++)
{
if ($aPosFinal[$i] < $aPosInicial[$i+1])
{
$Ok += 1;
}
else
{
$Ok -= 1;
}
}
if (($Ok + 1) == $nQuantTagInicial)
{
return TRUE;
}
else
{
return FALSE;
}
}
else
{
return FALSE;
}
}
function tagPHP($txt)
{
$fontInicial = '<font face="verdana" size="2" color="black">';
$fontFinal = '</font>';
$htmlInicial = '<table border="1" bgcolor="#F2F2F2" cellpadding="3"
cellspacing="0" width="500"><tr><td bordercolor="#F2F2F2">';
$htmlFinal = '</td></tr></table>';
$txt = preg_replace('/(\[(\/?)php\])/i', '[\\2php]', $txt);
$pma = preg_match_all('/\[php\](.+?)\[\/php\]/s', $txt, $match);
if ($pma && verifTag($txt))
{
foreach ($match[0] as $k => $v)
{
$v = nl2br(htmlentities($v));
$replace[$v] = $htmlInicial.highlight_string($match[1][$k], TRUE).$htmlFinal;
}
return $fontInicial.strtr(nl2br(htmlentities($txt)), $replace).$fontFinal;
}
else
{
return $fontInicial.nl2br(htmlentities($txt)).$fontFinal;
}
}
//*****
if (@$_POST["txt"])
// chamada
echo (get_magic_quotes_gpc()) ?
tagPHP(stripslashes($_POST["txt"])) : tagPHP($_POST["txt"]);
?>form.php
<form method="post" action="codephp.php"> <font face="verdana" size="2"> <b>Texto:</b></font><br /> <textarea name="txt" rows="8" cols="50"><? echo (get_magic_quotes_gpc()) ? stripslashes(@$_POST["txt"]) : @$_POST["txt"]; ?></textarea><br /> <font face="verdana" color="red" size="1"> <i>Obs.: O código será colorido apenas com o uso correto da tag.<br /> Não cite a tag dentro da tag.</i> </font><br /> <input type="submit" name="submit" value=" Visualizar "> </form>










