DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:readinifile

How to solve problem with parse_ini_file disabled

Include the override function for parse_ini_file in DokuWiki.

See at http://www.php.net/parse_ini_file, the function readINIfile (posted by “mhall at lakeland dot net”) works fine:

function readINIfile ($filename, $commentchar=';') {
  $array1 = file($filename);
  $section = '';
  for ($line_num = 0; $line_num <= sizeof($array1); $line_num++) {
   $filedata = $array1[$line_num];
   $dataline = trim($filedata);
   $firstchar = substr($dataline, 0, 1);
   if ($firstchar!=$commentchar && $dataline!='') {
     //It's an entry (not a comment and not a blank line)
     if ($firstchar == '[' && substr($dataline, -1, 1) == ']') {
       //It's a section
       $section = strtolower(substr($dataline, 1, -1));
     }else{
       //It's a key...
       $delimiter = strpos($dataline, '=');
       if ($delimiter > 0) {
         //...with a value
         $key = strtolower(trim(substr($dataline, 0, $delimiter)));
         $array2[$section][$key] = '';
         $value = trim(substr($dataline, $delimiter + 1));
         while (substr($value, -1, 1) == '\\') {
             //...value continues on the next line
             $value = substr($value, 0, strlen($value)-1);
             $array2[$section][$key] .= stripcslashes($value);
             $line_num++;
             $value = trim($array1[$line_num]);
         }
         $array2[$section][$key] .= stripcslashes($value);
         $array2[$section][$key] = trim($array2[$section][$key]);
         if (substr($array2[$section][$key], 0, 1) == '"' && substr($array2[$section][$key], -1, 1) == '"') {
            $array2[$section][$key] = substr($array2[$section][$key], 1, -1);
         }
       }else{
         //...without a value
         $array2[$section][strtolower(trim($dataline))]='';
       }
     }
   }else{
     //It's a comment or blank line.  Ignore.
   }
  }
  return $array2;
}

For instalation, remove 'parse_ini_file' from the string in install.php:

    $funcs = explode(' ','addslashes basename call_user_func chmod copy fgets '.
                         'file file_exists fseek flush filesize ftell fopen '.
                         'glob header ignore_user_abort ini_get mail mkdir '.
                         'ob_start opendir readfile realpath '.
                         'rename rmdir serialize session_start unlink usleep '.
                         'preg_replace file_get_contents');

After install, replace the function on lib\exe\css.php file:

$ini = readINIfile($tplinc.'style.ini');
tips/readinifile.txt · Last modified: 2012-02-28 21:52 by Andreas

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki