Subversion Repositories vgwhois

Rev

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

  1. <?php
  2.  
  3. #
  4. #  VGWhoIs (ViaThinkSoft Global WhoIs, a fork of generic Whois / gwhois)
  5. #  Common functions in PHP
  6. #
  7. #  (c) 2012-2018 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de>
  8. #
  9. #  License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2)
  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.  
  56.