94{
95 $ini = preg_split("/\r\n|\n/", $initext);
96 $secpattern = "/^\[(.[^\]]*)\]/i";
97
98
99 $entrypattern = "/^([a-z_0-9]*)\s*=\s*\"?([^\"]*)?\"?\$/i";
100 $strpattern = "/^\"?(.[^\"]*)\"?\$/i";
101
102 $section = array();
103 $sec = "";
104
105
106
107 static $words = array("yes", "on", "true", "no", "off", "false", "null");
108 static $values = array( 1, 1, 1, 0, 0, 0, null);
109
110
111
112 for($i = 0; $i < count($ini); $i++) {
113
114 $line = trim($ini[$i]);
115
116
117
118 if(strstr($line, '\"'))
119 $line = str_replace('\"', '/%quote%/', $line);
120
121
122
123 if($line == "" || preg_match("/^;/i", $line))
124 continue;
125
126 if(preg_match($secpattern, $line, $matches)) {
127
128
129
130 $sec = $matches[1];
131
132 if($changecase)
133 $sec = ucfirst(strtolower($sec));
134
135 $section[$sec] = array();
136
137 } elseif(preg_match($entrypattern, $line, $matches)) {
138
139
140
141 $entry = $matches[1];
142
143 if($changecase)
144 $entry = strtolower($entry);
145
146 $value = preg_replace($entrypattern, "\\2", $line);
147
148
149
150 $value = str_replace('/%quote%/', '"', $value);
151
152
153
154 if($convertwords) {
155 $index = array_search(strtolower($value), $words);
156 if($index !== false)
157 $value = $values[$index];
158 }
159
160 $section[$sec][$entry] = $value;
161
162 } else {
163
164
165
166 $section[$sec][] = preg_replace($strpattern, "\\1", $line);
167
168 }
169 }
170 return $section;
171}