]> jfr.im git - snippets.git/blob - snippets.php
Update LICENSE
[snippets.git] / snippets.php
1 <?php
2 function num2code($num, $dict) {
3 // Source: perl Acme::Tools
4 // License: GNU GPL v1+; Artistic License
5 if (!is_array($dict)) {
6 $dict = str_split($dict);
7 }
8 $base = count($dict);
9 $buf = array();
10 while ($num > 0) {
11 $buf[] = $dict[$num % $base];
12 $num = (int)($num/$base);
13 var_dump($num);
14 }
15 return implode(array_reverse($buf));
16 }
17
18 function code2num($str, $dict) {
19 // Source: perl Acme::Tools
20 // License: GNU GPL v1+; Artistic License
21 if (is_array($dict)) {
22 $dict = implode($dict);
23 }
24 $base = strlen($dict);
25 $buf = 0;
26 foreach (str_split($str) as $c) {
27 $buf = $buf*$base + strpos($dict, $c);
28 }
29 return $buf;
30 }
31
32 // vim: ts=4 nosmarttab noexpandtab