note 57075 added to function.parse-ini-file

From: Date: Thu, 22 Sep 2005 20:53:26 +0000
Subject: note 57075 added to function.parse-ini-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-95633@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57075 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57075&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57075&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57075&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57075&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57075&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57075&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57075&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57075&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95633) next »