/* ********** class configFile *********** constructor configFile (file name) - opens and reads in a configuration file function value (key name) - returns the value associated with a particular key example usage: $smb_conf = new configFile ("/etc/smb.conf"); $netbios_name = $smb_conf->value ("netbios name"); notes: * $__CLASS_CONFIGFILE__ is set to true to allow statements like if (!$__CLASS_CONFIGFILE__) include ("class.configFile.php"); * if a line's first non-space character is a '#' or ';" it is ignored. */ class configFile { // internal variables var $config_file; // name of configuration file var $config_values; // relational config array function configFile ($this_name) { // check to see if the file is there if (!file_exists ($this_name)) DIE ("configFile->constructor :: $this_name does not exist"); // open and parse $fp = fopen ($this_name, "r") OR DIE ("configFile->constructor :: could not open $this_name"); $this->config_file = $this_name; // set config file name while ($fl = fgets ($fp)) { $trimmed_line = trim ($fl); // trim it if ((substr ($trimmed_line, 0, 1) != '#') and (substr ($trimmed_line, 0, 1) != ';') and (strpos ($trimmed_line, "=") ) ) { $key = substr ($trimmed_line, 0, (strpos ($trimmed_line, "=")) ); $value = substr ($trimmed_line, (strpos ($trimmed_line, "=")+1) ); $this->config_values[trim($key)] = trim($value); // assign the value } // end if valid } // end of while loop // close the file fclose ($fp); } // end constructor configFile function value ($this_key) { return trim ($this->config_values[$this_key]); } // end function configFile->value function opushead ($titel) { $headanfang = " "; $headende = ""; printf("%s %s %s \n", $headanfang, $titel, $headende); } function opusfoot ($datei) { $datum=stat("$datei"); $modified = strftime("%d.%m.%y",$datum[10]); $footende = " - ama)\n\n\n< /BODY>\n"; printf("%s %s \n", $modified, $footende); } function connect($dbms) { if ($dbms == "mysql") { $sock = mysql_connect(); } elseif ($dbms == "msql") { $sock = msqlConnect(); } return $sock; } } // end class configFile