html_highlighter.php


Quell Code


<?php
function highlight_html($tmpCode){
  if(!defined('HLH_TAG')){
    # Highlight-Farben
    define('HLH_TAG', '#d02'); // HTML-Tag
    define('HLH_ATTR', '#00d'); // HTML-Tag-Attribut
    define('HLH_ATTR_VAL', '#090'); // HTML-Tag-Attribut-Wert
    define('HLH_JS', '#399'); // JavaScript
    define('HLH_PHP', '#970'); // PHP
    define('HLH_COMM', '#777'); // HTML-Kommentar
    define('HLH_ENT', '#e60'); // Entity
  }
  $tmpCode = htmlspecialchars($tmpCode);
  
  $tmpCode = str_replace("\t", '    ', $tmpCode);
  $tmpCode = str_replace(' ', '&nbsp;', $tmpCode);
  $tmpCode = str_replace('=', '&#61;', $tmpCode);
  # PHP-Code
  $tmpCode = preg_replace_callback('~&lt;\?(.*?)\?&gt;~is', 'hlh_htmlphp', $tmpCode);
  # Javascript
  $tmpCode = preg_replace_callback('~&lt;script(.*?)&gt;(.*?)&lt;/script&gt;~is', 'hlh_htmljs', $tmpCode);
  # Kommentar
  $tmpCode = preg_replace_callback('~&lt;!--(.*?)--&gt;~is', 'hlh_htmlcomm', $tmpCode);
  # Start-Tag (ohne Attribute)
  $tmpCode = preg_replace('~&lt;([a-z!]{1}[a-z0-9]{0,})&gt;~is', '&lt;<span style="color:'.HLH_TAG.'">$1</span>&gt;', $tmpCode);
  # Start-Tag
  $tmpCode = preg_replace_callback('~&lt;([a-z!]{1}[a-z0-9]{0,})&nbsp;(.*?)&gt;~is', 'hlh_htmltag', $tmpCode);
  # End-Tag
  $tmpCode = preg_replace('~&lt;\/([a-z]{1}[a-z0-9]{0,})&gt;~is', '&lt;/<span style="color:'.HLH_TAG.'">$1</span>&gt;', $tmpCode);
  # Entity
  $tmpCode = preg_replace('~&amp;([#a-z0-9]{1,20});~i', '<span style="color:'.HLH_ENT.'">&amp;$1;</span>', $tmpCode);
  
  $tmpCode = nl2br($tmpCode);
  return '<code>'.$tmpCode.'</code>';
}

function hlh_htmltag($code){ # Callback für Start-Tags
  $tag_name = $code[1];
  $tag_fill = $code[2];
  $tmp_tag = '&lt;<span style="color:'.HLH_TAG.'">'.$tag_name.'</span>&nbsp;';
  $tmp_tag.= preg_replace_callback('~([a-z-]+)&#61;([a-z0-9]{1,}|&quot;(.*?)&quot;|\'(.*?)\')~i', 'hlh_htmltagattr', $tag_fill);
  $tmp_tag.= '&gt;';
  return $tmp_tag;
}
function hlh_htmltagattr($code){ # Callback für Attribute
  $attr_name = $code[1];
  $attr_valwq = $code[2];
  return '<span style="color:'.HLH_ATTR.'">'.$attr_name.'</span>&#61;<span style="color:'.HLH_ATTR_VAL.'">'.$attr_valwq.'</span>';
}
function hlh_htmljs($code){ # Callback für Javascript
  $tag_fill = $code[1];
  $jsCode = $code[2];
  $jsCode = str_replace('&lt;', '&#60;', $jsCode);
  $jsCode = str_replace('&gt;', '&#62;', $jsCode);
  $jsCode = str_replace('&amp;', '&#38;', $jsCode);
  return '&lt;script'.$tag_fill.'&gt;<span style="color:'.HLH_JS.'">'.$jsCode.'</span>&lt;/script&gt;';
}
function hlh_htmlphp($code){ # Callback für PHP
  $phpCode = $code[1];
  $phpCode = str_replace('&lt;', '&#60;', $phpCode);
  $phpCode = str_replace('&gt;', '&#62;', $phpCode);
  $phpCode = str_replace('&amp;', '&#38;', $phpCode);
  $phpCode = str_replace('&quot;', '&#34;', $phpCode);
  $phpCode = str_replace("'", '&#39;', $phpCode);
  return '<span style="color:'.HLH_PHP.'">&#60;?'.$phpCode.'?&#62;</span>';
}
function hlh_htmlcomm($code){ # Callback für Kommentare
  $phpCode = $code[1];
  $phpCode = str_replace('&lt;', '&#60;', $phpCode);
  $phpCode = str_replace('&gt;', '&#62;', $phpCode);
  $phpCode = str_replace('&amp;', '&#38;', $phpCode);
  return '<span style="color:'.HLH_COMM.'">&#60;!--'.$phpCode.'--&#62;</span>';
}
?>
 
<?php
$code = '<div style="color:olive;">
 <strong>nur zwei &euro;!</strong>
</div>';//Dieser Code wird  dann in Farbe dargestellt
echo highlight_html($code);
?>
 


Deprecated: Directive 'allow_url_include' is deprecated in Unknown on line 0
vConsole
21:34:18
Uncaught TypeError: Cannot read properties of null (reading 'style')
/loesungen/index.php?name=html_highlighter.php:5446:53
21:34:19
Uncaught SyntaxError: Unexpected token '<'
/js/index.php?js=3.2.1-jquery.min.js:4:22481
21:34:20
Uncaught SyntaxError: Unexpected token '<'
/js/index.php?js=MooTools.min.js:5:5095
21:34:20
Uncaught SyntaxError: Unexpected token '<'
/js/index.php?js=EnlighterJS.min.js:3:17773
21:34:20
Uncaught TypeError: window.addEvent is not a function
/loesungen/index.php?name=html_highlighter.php:2786:8
21:34:20
Uncaught SyntaxError: Unexpected token '<'
/js/index.php?js=pace.js:896:26
21:34:20
Uncaught SyntaxError: Unexpected token '<'
/js/index.php?js=cookieconsent.min.js:1:20809
21:34:20
Uncaught SyntaxError: Unexpected token '<'
/js/alljs.php:408:2
21:34:20
500
21:34:18
WeChatLib: 0 (xxxx.xx.xx)
21:34:21
System: Unknown
21:34:21
Protocol: HTTPS
21:34:21
UA: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
21:34:21
navigationStart: 1739223257640
21:34:21
navigation: 606ms
21:34:21
dns: 32ms
21:34:21
tcp (ssl): 227ms (116ms)
21:34:21
request: 323ms
21:34:21
response: 111ms
21:34:21
domComplete (domLoaded): 2276ms (1191ms)
21:34:21
loadEvent: 25ms
21:34:21
total (DOM): 3492ms (3467ms)