note 91629 added to function.parse-ini-file

From: Date: Sat, 20 Jun 2009 07:46:44 +0000
Subject: note 91629 added to function.parse-ini-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-157169@lists.php.net to get a copy of this message
I'm not sure why, but for some reason php's ini functions always leave out entries for me. To solve this problem, I wrote my own ini parsing function, intended to be a replacement for parse_ini_file('file.ini', true); <?php function new_parse_ini($f) { // if cannot open file, return false if (!is_file($f)) return false; $ini = file($f); // to hold the categories, and within them the entries $cats = array(); foreach ($ini as $i) { if (@preg_match('/\[(.+)\]/', $i, $matches)) { $last = $matches[1]; } elseif (@preg_match('/(.+)=(.+)/', $i, $matches)) { $cats[$last][$matches[1]] = $matches[2]; } } return $cats; } ?> The usage follows the Example #2 on http://us3.php.net/manual/en/function.parse-ini-file.php , except without the second parameter being 'true'. ---- Server IP: 209.41.74.194 Probable Submitter: 65.34.27.38 ---- Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php Edit -- https://master.php.net/note/edit/91629 Del: integrated -- https://master.php.net/note/delete/91629/integrated Del: useless -- https://master.php.net/note/delete/91629/useless Del: bad code -- https://master.php.net/note/delete/91629/bad+code Del: spam -- https://master.php.net/note/delete/91629/spam Del: non-english -- https://master.php.net/note/delete/91629/non-english Del: in docs -- https://master.php.net/note/delete/91629/in+docs Del: other reasons-- https://master.php.net/note/delete/91629 Reject -- https://master.php.net/note/reject/91629 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157169) next »