[phptag][/phptag] functie probleempje
Stel dat de eerste [phptag]tekst[/phptag] 8 regels bevat. dan doet hij bij de 2e en 3e [phptag][/phptag] ook 8 regels. Ook highlight de functie enkel de eerste inhoud van [phptag][/phptag]
Code (php)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
function php_code($text){
$matches = array();
$match_count = preg_match_all("/\[phptag\](.*?)\[\/phptag\]/sie", $text, $matches);
for ($i = 1; $i <= $match_count; $i++) {
$before_replace = $matches[$i][0];
$after_replace = trim($matches[$i][0]);
$str_to_match = "[phptag]" . $before_replace . "[/phptag]";
$after_replace = str_replace('<', '<', $after_replace);
$after_replace = str_replace('>', '>', $after_replace);
$after_replace = str_replace('&', '&', $after_replace);
$after_replace = str_replace('"', '"', $after_replace);
$after_replace = str_replace('<br />', '', $after_replace);
$added = FALSE;
if (preg_match('/^<\?.*?\?>$/si', $after_replace) <= 0) {
$after_replace = "<?php $after_replace ?>";
$added = TRUE;
}
if(strcmp('4.2.0', phpversion()) > 0) {
ob_start();
highlight_string($after_replace);
$after_replace = ob_get_contents();
ob_end_clean();
} else {
$after_replace = highlight_string($after_replace, TRUE);
}
if ($added == TRUE) {
$after_replace = substr_replace($after_replace, '', strpos($after_replace, '<?php' ), 14);
$after_replace = substr_replace($after_replace, '' , strrpos($after_replace, '?>'), 5);
}
$a = explode("<br />", $after_replace);
$b = explode("\n", $after_replace);
$c = count($a);
$d = count($b);
$data = $c + $d;
for($i=1; $i <= $data; $i++) {
$nummers .= $i."<br>";
}
$php_start_html = "<div class='quote'><table border='0' width='100%' cellpadding='3' cellspacing='0'>
<tr>
<td width='100%' colspan='2' bgcolor='#A2CAE1'><font face='Verdana' size='1'>Code:</font></td>
</tr>
<tr>
<td align='right' bgcolor='#DDDDDD'><code style=\"color: #666666\">". $nummers ."</code></td>
<td valign='top' width='100%' bgcolor='#FFFFFF'><code>";
$php_end_html = "</code></td>
</tr>
</table></div>";
$replacement = $php_start_html;
$after_replace = preg_replace('/<font color="(.*?)">/si', '<span style="color: \\1;">', $after_replace);
$after_replace = str_replace('</font>', '</span>', $after_replace);
$after_replace = str_replace("\n", '', $after_replace);
$replacement .= $after_replace;
$replacement .= $php_end_html;
$text = str_replace($str_to_match, $replacement, $text);
}
$text = str_replace("[phptag]", $php_start_html, $text);
$text = str_replace("[/phptag]", $php_end_html, $text);
return $text;
}
?>
function php_code($text){
$matches = array();
$match_count = preg_match_all("/\[phptag\](.*?)\[\/phptag\]/sie", $text, $matches);
for ($i = 1; $i <= $match_count; $i++) {
$before_replace = $matches[$i][0];
$after_replace = trim($matches[$i][0]);
$str_to_match = "[phptag]" . $before_replace . "[/phptag]";
$after_replace = str_replace('<', '<', $after_replace);
$after_replace = str_replace('>', '>', $after_replace);
$after_replace = str_replace('&', '&', $after_replace);
$after_replace = str_replace('"', '"', $after_replace);
$after_replace = str_replace('<br />', '', $after_replace);
$added = FALSE;
if (preg_match('/^<\?.*?\?>$/si', $after_replace) <= 0) {
$after_replace = "<?php $after_replace ?>";
$added = TRUE;
}
if(strcmp('4.2.0', phpversion()) > 0) {
ob_start();
highlight_string($after_replace);
$after_replace = ob_get_contents();
ob_end_clean();
} else {
$after_replace = highlight_string($after_replace, TRUE);
}
if ($added == TRUE) {
$after_replace = substr_replace($after_replace, '', strpos($after_replace, '<?php' ), 14);
$after_replace = substr_replace($after_replace, '' , strrpos($after_replace, '?>'), 5);
}
$a = explode("<br />", $after_replace);
$b = explode("\n", $after_replace);
$c = count($a);
$d = count($b);
$data = $c + $d;
for($i=1; $i <= $data; $i++) {
$nummers .= $i."<br>";
}
$php_start_html = "<div class='quote'><table border='0' width='100%' cellpadding='3' cellspacing='0'>
<tr>
<td width='100%' colspan='2' bgcolor='#A2CAE1'><font face='Verdana' size='1'>Code:</font></td>
</tr>
<tr>
<td align='right' bgcolor='#DDDDDD'><code style=\"color: #666666\">". $nummers ."</code></td>
<td valign='top' width='100%' bgcolor='#FFFFFF'><code>";
$php_end_html = "</code></td>
</tr>
</table></div>";
$replacement = $php_start_html;
$after_replace = preg_replace('/<font color="(.*?)">/si', '<span style="color: \\1;">', $after_replace);
$after_replace = str_replace('</font>', '</span>', $after_replace);
$after_replace = str_replace("\n", '', $after_replace);
$replacement .= $after_replace;
$replacement .= $php_end_html;
$text = str_replace($str_to_match, $replacement, $text);
}
$text = str_replace("[phptag]", $php_start_html, $text);
$text = str_replace("[/phptag]", $php_end_html, $text);
return $text;
}
?>
Gewijzigd op 01/01/1970 01:00:00 door Bas verhagen
waarom allemaal handmatig? highlight_string() heb je daar ook voor.
Ik gebruik toch ook de highlight_string() ? :P