javascript-phps-printr-functie-in-js
Gesponsorde koppelingen
PHP script bestanden
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
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
<?php
function print_r(array,lfchar,wschar,lvl) {
if(!wschar) {wschar = ' ';}
if(!lfchar) {lfchar = '<br/>';}
if(!lvl) {lvl = 0;}
var output = '';
if(typeof(array)=='object') {
var a=0;
output += 'array(<br/>';
lvl++;
while(a<array.length) {
output += str_repeat(' ',lvl)+'['+a+'] = '+print_r(array[a],lfchar,wschar,lvl)+'<br/>';
a++;
}
lvl--;
output += str_repeat(' ',lvl)+')';
} else {
output = array;
}
return output;
}
//repeat a string for the given times
function str_repeat(str,times) {
var a=0;
output = '';
str = str.toString();
while(a<times) {
output += str;
a++;
}
return output;
}
?>
function print_r(array,lfchar,wschar,lvl) {
if(!wschar) {wschar = ' ';}
if(!lfchar) {lfchar = '<br/>';}
if(!lvl) {lvl = 0;}
var output = '';
if(typeof(array)=='object') {
var a=0;
output += 'array(<br/>';
lvl++;
while(a<array.length) {
output += str_repeat(' ',lvl)+'['+a+'] = '+print_r(array[a],lfchar,wschar,lvl)+'<br/>';
a++;
}
lvl--;
output += str_repeat(' ',lvl)+')';
} else {
output = array;
}
return output;
}
//repeat a string for the given times
function str_repeat(str,times) {
var a=0;
output = '';
str = str.toString();
while(a<times) {
output += str;
a++;
}
return output;
}
?>
i: kopieer niet de < ?php en ? >. Deze heb ik enkel erbij geplakt voor syntax-highlighting.