Ho risolto ma dovrei far visualizzare il codice html e sto usando una classe
classe:
Codice PHP:
<?php
class sourcecode
{
function html($str)
{
$str = preg_replace("/()/", "(%comment_b%)\\2(%comment_e%)", $str); // Replace COMMENTs
$tag_array = preg_split("/(<.+?>)/", $str, -1, PREG_SPLIT_DELIM_CAPTURE); // Breake by TAGs to array
while (list($ar_counter,$ar_value) = each($tag_array)) // walk array
{
if ($ar_counter % 2 != 0)
{
// <TAG ATTRIBUTE="VALUE" />
//replace <(%tag_b%)TAG(%span_e%) (%attribute_b%)ATTRIBUTE(%span_e%)=(%velue_b%)"VALUE"(%span_e%) />
$re=array("/(<+)([\/]?)(\S+)(>| [^>]*>)/", "/ (\S+)( *= *)([\"']?)([^\"'>]+)([\"' \?>]?)/");
$replacement=array( "\\1\\2(%tag_b%)\\3(%span_e%)\\4", " (%attribute_b%)\\1(%span_e%)\\2(%value_b%)\\3\\4\\5(%span_e%)");
$ar_value=preg_replace($re,$replacement,$ar_value);
$ar_value=htmlspecialchars($ar_value);
// replace signs (%something%) to span HTML TAGs
$ar_value=str_replace("(%tag_b%)", "<span class=\"tag\">", $ar_value);
$ar_value=str_replace("(%value_b%)", "<span class=\"value\">", $ar_value);
$ar_value=str_replace("(%attribute_b%)", "<span class=\"attribute\">", $ar_value);
$ar_value=str_replace("(%span_e%)", "</span>", $ar_value);
} else
{
// replace signs (%something%) to span HTML TAGs
$ar_value=str_replace("(%comment_b%)", "<span class=\"comment\"><!--", $ar_value);
$ar_value=str_replace("(%comment_e%)", "--></span>", $ar_value);
}
$res.=nl2br($ar_value);
}
return "<span class=\"text\">$res</span>"; // return RESULT close in tags SPAN
}
}
?>
file php
Codice PHP:
<html>
<head><title>Genera tabelle per MyBB</title>
<style type="text/css">
<style>
.code
{
text-align:left;
font-size:9px;
font-family: 'Fixedsys', 'courier new', courier, fixed;s
}
.code span.text
{
color:#000000;
}
.code span.comment
{
color:#008000;
}
.code span.tag
{
color:#0000BB;
}
.code span.attribute
{
color:#DD0000;
}
.code span.value
{
color:#800080;
}
.code span.comment span
{
color:#008000;
}
</style>
</head>
<body>
<?php
include("hig.php");
$hig = new sourcecode;
$sottotitolo = htmlspecialchars($_POST['sottotitolo']);
$righe = htmlspecialchars($_POST['righe']);
$colonne = htmlspecialchars($_POST['colonne']);
function table() {
$table="<table border=\"1\">";
if ($sottotitolo == 1) {
$table.="<tr><td colspan=\"$colonne\">Sottotitolo</td></tr>";
}
for($i=j;$j<$righe;$j++){
echo "<tr>";
for($i=1;$i<=$colonne;$i++){
$table.="<td>Colonna $i</td>";
}
$table.="</tr>";
}
$table.="</table>";
return $table;
}
$table = table();
echo "<p class=\"code\">".$hig->html($table)."</p>";
?>
<form action="" method="POST">
Righe: <input type="text" size="3" name="righe">
Colonne: <input type="text" size="3" name="colonne">
Sottotitolo: <select name="sottotitolo">
<option value="1">Si</option>
<option value="0">No</option></select>
<input type="submit" value="Crea">
</form>
</body>
</html>
Il problema è che mi printa sempre <table border="1"></table>