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

From: Date: Sun, 15 Sep 2019 12:59:04 +0000
Subject: note 57075 deleted from function.parse-ini-file by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212183@lists.php.net to get a copy of this message
Note Submitter: Julio López Garbayo <sinedeo at gmail dot com> ---- I wrote a replacement function with following changes: -It allows quotes and double quotes. -It detects wether your .ini file has sections or not. -It will read until eof in any case, even if a line contains errors. I know it can be improved a lot, so feel free to work on it and, please, notify me if you do. <?php function parse_ini_file_quotes_safe($f) { $r=$null; $sec=$null; $f=@file($f); for ($i=0;$i<@count($f);$i++) { $newsec=0; $w=@trim($f[$i]); if ($w) { if ((!$r) or ($sec)) { if ((@substr($w,0,1)=="[") and (@substr($w,-1,1))=="]") {$sec=@substr($w,1,@strlen($w)-2);$newsec=1;} } if (!$newsec) { $w=@explode("=",$w);$k=@trim($w[0]);unset($w[0]); $v=@trim(@implode("=",$w)); if ((@substr($v,0,1)=="\"") and (@substr($v,-1,1)=="\"")) {$v=@substr($v,1,@strlen($v)-2);} if ($sec) {$r[$sec][$k]=$v;} else {$r[$k]=$v;} } } } return $r; } ?>

« previous php.notes (#212183) next »