Html farblich darstellen.
function highlight_html($string,$CodeColor) {
//> HTML Tags definieren und farben zuweisen.
$parse_tags = array("script" => "#990000",
"a" => "#009900",
"*img" => "#990099",
"style" => "#990099",
"form" => "#ff9900",
"textarea" => "#ff9900",
"select" => "#ff9900",
"option" => "#ff9900",
"input" => "#ff9900",
"table" => "#009999",
"th" => "#009999",
"td" => "#009999",
"tr" => "#009999",
"tbody" => "#009999",
"tfoot" => "#009999");
//> Restliche Htmlelemente frben
$parse_elements = array(//> Fr Format: &xxxx;
"#000000",
//> Fr Format: 'xxxx' und "xxxx"
"#0000ff",
//> Tags die keine definition haben.
"#000099",
//> Farbe fr Kommentare.
"#999999",
//> Farbe in style tags fr den Anfhrungszeichen
"#006600",
//> Farbe in script Tags fr die Anfhrungszeichen
"#000000",
//> Default farbe fr nicht definierten Code.
$CodeColor);
//> Tags farblich hervorheben!
while(list($tag,$color) = each($parse_tags)) {
if(substr($tag,0,1) == "*" && $tag != "#") {
//> Offene Tags frben(fr die Tags die keine end- Tags besitzen!)
$pattern[] = "%<".substr($tag,1)."(.+)>%Uis";
$replace[] = "<".substr($tag,1)."$1>";
} else {
//> Offene Tags frben!
$pattern[] = "%<".$tag."(.+)>%Uis";
$replace[] = "<".$tag."$1>";
//> Geschlossene Tags frben!
$pattern[] = "%</".$tag.">%Uis";
$replace[] = "</".$tag.">";
}
}
//> Formatierung farblich hervorheben Beispiel: &xxxx;
$pattern[] = "%&([a-zA-Z0-9#]+);%Uis";
$replace[] = "&$1;";
//> Formatierung farblich hervorheben Beispiel: 'xxxx'
$pattern[] = "%'(.*)'%esiU";
$replace[] = "_html_quotes('\$1','\'','".$parse_elements[1]."')";
//> Formatierung farblich hervorheben Beispiel: "xxxx"
$pattern[] = "%"(.*)"%esiU";
$replace[] = "_html_quotes('\$1','"','".$parse_elements[1]."')";
//> Kommentar farblich hervorheben Beispiel: ;
$pattern[] = "%<!--(.*)-->%esiU";
$replace[] = "_html_comments('\$1','".$parse_elements[3]."')";
//> Ausfhrungszeichen in style- Tags farblich hervorheben.
$pattern[] = "%<style(.*)>%esiU";
$replace[] = "_html_styletag('\$1','".$parse_elements[4]."')";
//> Ausfhrungszeichen in script- Tags farblich hervorheben.
$pattern[] = "%<script(.*)>%esiU";
$replace[] = "_html_scripttag('\$1','".$parse_elements[5]."')";
//> CSS Code inerhalb eines Tags entsprechend hervorheben.
$pattern[] = "%style( =| = |= |=)(.+)%esiU";
$replace[] = "_html_style('\$2')";
//> CSS Code farblich hervorheben. (ggf. an Modul weiterleiten.)
if(function_exists("highlight_css")) {
$pattern[] = "%(<style)(.*)(>)(.*)(<\/style>)%esiU";
$replace[] = "highlight_css('\$4','\$1\$2\$3','\$5')";
} else {
$pattern[] = "%(<style)(.*)(>)(.*)(<\/style>)%esiU";
$replace[] = "_html_defaultcode('\$4','\$1\$2\$3','\$5','".$parse_elements[6]."')";
}
//> JavaScript Code farblich hervorheben. (ggf. an Modul weiterleiten. Dazu bitte selber if bedingung basteln!!!)
$pattern[] = "%(<script)(.*)(>)(.*)(<\/script>)%esiU";
$replace[] = "_html_defaultcode('\$4','\$1\$2\$3','\$5','".$parse_elements[6]."')";
$string = str_replace("<","<",$string);
$string = str_replace(">",">",$string);
$string = preg_replace($pattern,$replace,$string);
return stripslashes($string);
}
//> Sub funktion fr die Funktion "xxxx" und 'xxxx'
function _html_quotes($string,$type,$color) {
//> Farb- Tags () und Formatierungs- Tags () Lschen.
$pattern = array("%%siU",
"%%siU",
"%<(i|b)>%siU",
"%(i|b)>%siU");
$string = preg_replace($pattern,"",$string);
return "".$type.$string.$type."";
}
//> Sub Funktion um CSS Code inerhalb eines Tags entsprechend hervorheben.
function _html_style($string) {
//> Farb- Tags () Lschen.
$pattern = array("%%siU",
"%%siU");
$string = preg_replace($pattern,"",$string);
unset($pattern);
$pattern[] = "%("|')%siU";
$replace[] = "$1";
$pattern[] = "%:(.+);%siU";
$replace[] = ":$1;";
$string = preg_replace($pattern,$replace,$string);
return "style=".$string."";
}
//> Sub Funktion um in die Anfhrungszeichen anders farblich hervorzuheben.
function _html_styletag($string,$color) {
//> Farb- Tags () und Formatierungs- Tags () Lschen.
$pattern = array("%%siU",
"%%siU");
$string = preg_replace($pattern,"",$string);
unset($pattern);
$pattern[] = "%"(.+)"%siU";
$replace[] = ""$1"";
$pattern[] = "%'(.+)'%siU";
$replace[] = "'$1'";
$string = preg_replace($pattern,$replace,$string);
return "<style".$string.">";
}
//> Sub Funktion um in die Anfhrungszeichen anders farblich hervorzuheben.
function _html_scripttag($string,$color) {
//> Farb- Tags () und Formatierungs- Tags () Lschen.
$pattern = array("%%siU",
"%%siU");
$string = preg_replace($pattern,"",$string);
unset($pattern);
$pattern[] = "%"(.+)"%siU";
$replace[] = ""$1"";
$pattern[] = "%'(.+)'%siU";
$replace[] = "'$1'";
$string = preg_replace($pattern,$replace,$string);
return "<script".$string.">";
}
//> Sub Funktion um Kommentare Farblich hervorzuheben.
function _html_comments($string,$color) {
//> Farb- Tags () und Formatierungs- Tags () Lschen.
$pattern = array("%%siU",
"%%siU",
"%<(i|b)>%siU",
"%(i|b)>%siU");
$string = preg_replace($pattern,"",$string);
return "<!--".$string."-->";
}
//> Sub Funktion um Farben zu lschen und text in anderer Farbe darzustellen.
function _html_defaultcode($string,$stag,$etag,$color) {
//> Farb- Tags () und Formatierungs- Tags () Lschen.
$pattern = array("%%siU",
"%%siU",
"%<(i|b)>%siU",
"%(i|b)>%siU");
$string = preg_replace($pattern,"",$string);
return $stag."".$string."".$etag;
}
?>