Subversion Repositories vgwhois

Rev

Rev 5 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
<?php
2
 
3
#
11 daniel-mar 4
#  VGWhoIs (ViaThinkSoft Global WhoIs, a fork of generic Whois / gwhois)
5 daniel-mar 5
#  Common functions in PHP
2 daniel-mar 6
#
5 daniel-mar 7
#  (c) 2012-2018 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de>
2 daniel-mar 8
#
5 daniel-mar 9
#  License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2)
2 daniel-mar 10
#
11
 
12
function parse_config($file) {
13
        if (!file_exists($file)) return false;
14
 
15
        $count = 0;
16
 
17
        $cont = file($file);
18
        foreach ($cont as $c) {
19
                $c = trim($c);
20
 
21
                if ($c == '') continue;
22
                if ($c[0] == '#') continue;
23
 
24
                $c = preg_replace('@(.+)\\s#.+$@U', '\\1', $c);
25
 
26
                $ary = explode('=', $c, 2);
27
                $name = trim($ary[0]);
28
                $val = trim($ary[1]);
29
 
30
                // true/false does not work for bash, so we do not accept it here either
31
                /*
32
                if (strtolower($val) === 'no') $val = false;
33
                if (strtolower($val) === 'false') $val = false;
34
                if (strtolower($val) === 'yes') $val = true;
35
                if (strtolower($val) === 'true') $val = true;
36
                */
37
 
38
                $val = str_strip_quotes($val);
39
 
40
                define($name, $val);
41
                $count++;
42
        }
43
 
44
        return $count;
45
}
46
 
47
function str_strip_quotes($x) {
48
        if (((substr($x,0,1) == '"') && (substr($x,-1,1) == '"')) ||
49
            ((substr($x,0,1) == "'") && (substr($x,-1,1) == "'"))) {
50
                return substr($x,1,strlen($x)-2);
51
        } else {
52
                return $x;
53
        }
54
}
55