note 91629 deleted from function.parse-ini-file by cmb

From: Date: Sun, 02 Dec 2018 12:48:26 +0000
Subject: note 91629 deleted from function.parse-ini-file by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209826@lists.php.net to get a copy of this message
Note Submitter: joe at u13 dot net ---- 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'.

« previous php.notes (#209826) next »