All pastes #925707 Raw Edit

Stuff

public text v1 · immutable
·published 2008-03-03 05:52 UTC
rendered paste body
function read_ini_file($f, &$r)
    {
    	$dumbcounter = 0;
        $null = "";
        $r=$null;
        $first_char = "";
        $sec=$null;
        $comment_chars=";#";
        $num_comments = "0";
        $num_newline = "0";

        //Read to end of file with the newlines still attached into $f
        $f = @file($f);
        if ($f === false) {
            return -2;
        }

        // Process all lines from 0 to count($f)
        for($i = 0; $i < count($f); $i++) {
        	$w = trim($f[$i]);
        	$first_char = substr($w, 0, 1);
        	if($w) {
        		if( (substr($w, 0 ,1) == "[") && (substr($w, -1, 1) == "]") ) {
        			$sec = substr($w, 1, strlen($w) - 2);
        			$num_comments = 0;
        			$num_newline = 0;
        		} else if( (stristr($comment_chars, $first_char) == True)) {
        			$r[$sec]["Comment_".$num_comments] = $w;
        			$num_comments++;
        		} else {
					$w = explode("=", $w);
					$k = trim($w[0]);
					unset($w[0]);
					$v = trim(implode("=", $w));
					if( (substr($v, 0, 1) == "\"") && (substr($v, -1, 1) == "\"") ) {
						$v = substr($v, 1, strlen($v) - 2);
					}
					print_r($sec . " " . $k . "\n");
					print_r($r[$sec]);
					print_r($r[$sec][$k]);
					//if($r[$sec][$k] != '')
					//	$k = $k . $dumbcounter++;
					$r[$sec][$k]=$v;
        		}
        	} else {
        		$r[$sec]["Newline_".$num_newline] = $w;
        		$num_newline++;
            }
        }
        return 1;
    }