35       $configData = array();
 
   36       $currentSection = 
false;
 
   39       if (!file_exists($file) || !is_readable($file)) {
 
   43       $fp = fopen($file, 
'rb');
 
   49          $line = fgets($fp, 1024);
 
   51          if ($line === 
'' || strpos($line, 
';') === 0) {
 
   56          if (preg_match(
'/^\[(.+)\]/', $line, $matches)) {
 
   58             $currentSection = $matches[1];
 
   59             if (!isset($configData[$currentSection])) {
 
   60                $configData[$currentSection] = array();
 
   63          } 
else if (strpos($line, 
'=') !== 
false) {
 
   65             list($key, $value) = explode(
'=', $line, 2);
 
   67             $value = trim($value);
 
   70             if (preg_match(
'/^[\"\'](.*)[\"\']$/', $value, $matches)) {
 
   72                $value = stripslashes($matches[1]);
 
   75                preg_match(
'/^([\S]*)/', $value, $matches);
 
   82                } 
else if (is_numeric($value)) {
 
   83                   if (strstr($value, 
'.')) {
 
   85                      $value = (float) $value;
 
   86                   } 
else if (substr($value, 0, 2) == 
'0x') {
 
   88                      $value = intval($value, 16);
 
   89                   } 
else if (substr($value, 0, 1) == 
'0') {
 
   91                      $value = intval($value, 8);
 
   94                      $value = (int) $value;
 
   97                } 
else if (strtolower($value) == 
'true' || strtolower($value) == 
'on') {
 
  100                } 
else if (strtolower($value) == 
'false' || strtolower($value) == 
'off') {
 
  103                } 
else if (defined($value)) {
 
  105                   $value = constant($value);
 
  109             if ($currentSection === 
false) {
 
  110                $configData[$key] = $value;
 
  112             } 
else if (is_array($configData[$currentSection])) {
 
  113                $configData[$currentSection][$key] = $value;
 
  132       if (!file_exists($file) || !is_readable($file)) {
 
  137       $lines = file($file);
 
  140       for ($i=0, $count=count($lines); $i < $count; $i++) {
 
  143          if (preg_match(
'/^;/', $line) || preg_match(
'/^\s*$/', $line)) {
 
  145             $this->content .= $line;
 
  147          } 
else if (preg_match(
'/^\s*\[(\w+)\]/', $line, $matches)) {
 
  149             $currentSection = $matches[1];
 
  150             $this->content .= $line;
 
  152          } 
else if (preg_match(
'/^\s*(\w+)\s*=/', $line, $matches)) {
 
  156             if (!isset($currentSection) && array_key_exists($key, $params) && !is_array($params[$key])) {
 
  158                $value = $params[$key];
 
  160             } 
else if (isset($params[$currentSection]) && is_array($params[$currentSection]) && array_key_exists($key, $params[$currentSection])) {
 
  162                $value = $params[$currentSection][$key];
 
  166                $this->content .= $line;
 
  170             if (preg_match(
'/[^\w\-\/]/', $value)) {
 
  172                $valueString = 
'"' . addslashes($value) . 
'"';
 
  174                $valueString = $value;
 
  177             $this->content .= 
"$key = $valueString\n";
 
  180             $this->content .= $line;
 
  193       if (!(file_exists($file) && is_writable($file))
 
  194          && !(!file_exists($file) && is_dir(dirname($file)) && is_writable(dirname($file)))) {
 
  199       $fp = @fopen($file, 
'wb');
 
  204       fwrite($fp, $this->content);