-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathfunction.php
63 lines (58 loc) · 1.73 KB
/
function.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
<?php
function json_format($json) {
$p = '';
$nbtab = 0;
$tab = " ";
$out = "";
for($i=0; $i<strlen($json); $i++) {
$c = $json[$i];
$n = isset($json[$i+1]) ? $json[$i+1] : '';
switch($c) {
case '[':
case '{':
if($p == ':') { $nbtab++; $out .= "\n".str_repeat($tab, max(0, $nbtab)); }
$out .= $c."\n".str_repeat($tab, max(0, ++$nbtab));
break;
case ']':
case '}':
$nbtab--;
$out .= "\n".str_repeat($tab, max(0, $nbtab)).$c;
#if($c == '}' && $n != ',') { $nbtab--; }
if($c == ']') { $nbtab--; }
break;
case ',':
if(in_array($p, array(']','}','"'))) {
#if($p == ']') { $nbtab--; }
$out .= $c."\n".str_repeat($tab, max(0, $nbtab));
} else {
$out .= $c;
}
break;
case ':':
if($p == '"') { $out .= ' '; }
$out .= $c;
if($p == '"') { $out .= ' '; }
break;
default:
$out .= $c;
break;
}
$p = $c;
}
return $out;
}
function idna_to_unicode($name) {
exec("LANG=en_US.UTF-8 /usr/bin/idn --allow-unassigned --usestd3asciirules --profile=Nameprep --idna-to-unicode '".$name."'", $out);
if(count($out)) {
return $out[0];
}
return false;
}
function unicode_to_idna($name) {
exec("LANG=en_US.UTF-8 /usr/bin/idn --allow-unassigned --usestd3asciirules --profile=Nameprep --idna-to-ascii '".$name."'", $out);
if(count($out)) {
return strtolower($out[0]);
}
return false;
}
?>