1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
|
<?php
/**
* Highlight Klasse
* @version 0.0
* @author benjamin <spam@abba-skript.de>
*
* Diese Klasse dient zum hervorheben von Html und PHP Code.
*/
class highlight {
private $ersetzen = array(array());
private $codes = array(array());
/**
* PHP Code einfärben
* @param string $text Text zum einfärben
* @return string eingefärbter PHP Code wird zurück gegeben.
*/
public function php($text) {
$text = highlight_string($text, TRUE);
return $text;
}
/**
* HTML Code einfärben
* @param string $text Text zum einfärben
* @return string eingefärbter HTML Code wird zurück gegeben.
*/
public function html($text) {
$text = htmlspecialchars($text);
$this -> ersetzen("<", "<span style=\"color: green;\"><");
$this -> ersetzen(">", "></span>");
$this -> codes("/"(.*)"/Usi", "<span style=\"color: red;\">"\\1"</span>");
$this -> codes("/<!--(.*)-->/Usi", "<span style=\"color: blue;\"><!--\\1--></span>");
$this -> ersetzen("\t", " ");
$text = str_replace($this -> ersetzen[0], $this -> ersetzen[1], $text);
$text = preg_replace($this -> codes[0], $this -> codes[1], $text);
return "<code>".nl2br($text)."</code>";
}
private function ersetzen($name, $wert) {
if (!empty($name)) {
$anzahl = (count($this -> ersetzen, COUNT_RECURSIVE)/2-1);
$this -> ersetzen[0][$anzahl] = $name;
$this -> ersetzen[1][$anzahl] = $wert;
}
}
private function codes($v1, $v2) {
if (!empty($v1) and !empty($v2)) {
$anzahl = (count($this -> codes, COUNT_RECURSIVE)/2-1);
$this -> codes[0][$anzahl] = $v1;
$this -> codes[1][$anzahl] = $v2;
}
}
}
|