Re: parse_ini_file() seems to be broken in PHP 5.2.4-2ubuntu5.12
| From: | Thijs Lensselink | Date: | Thu, 11 Nov 2010 10:30:13 +0000 |
| Subject: | Re: parse_ini_file() seems to be broken in PHP 5.2.4-2ubuntu5.12 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-309445@lists.php.net to get a copy of this message | ||
On Wed, 10 Nov 2010 18:08:01 -0800, "Daevid Vincent" <daevid@daevid.com> wrote:
http://php.net/manual/en/function.parse-ini-file.php Why doesn't PHP parse the 'null', 'true', 'false', etc into their proper equivalents? What's worse is that it does this mangling of my RAW values to be strings and sets them to "1" !!! WTF good does that do me?! Here is my test.ini file: --------------------------------------------------------------------------- ---------------------------Use the third parameter so the orignal values wil not get converted (still strings though) Besides that are you sure there are no whitespaces behind the ini values? var_dump([examples] ; this is a section ; this is a comment linelog_level = E_ALL & ~E_NOTICE1 = intkey ; this is a int key nullvalue = null ; this is NULL truebool = true ; this is boolean (TRUE) falsebool = false ; this is boolean (FALSE) intvalue = -1 ; this is a integer (-1) floatvalue = +1.4E-3 ; this is a float (0.0014) stringvalue = Hello World ; this is a unquoted string quoted = "Hello World" ; this is a quoted string apostrophed = 'Hello World' ; this is a apostrophed string quoted escaped = "it work's \"fine\"!" ; this is a quoted string withescaped quotes apostrophed escaped = 'it work\'s "fine"!' ; this is a apostrophed string with escaped apostrophes --------------------------------------------------------------------------- --------------------------- Here is my test.php page: --------------------------------------------------------------------------- --------------------------- <?php var_dump(parse_ini_file('./test.ini', true)); ?> --------------------------------------------------------------------------- --------------------------- Here is the output: --------------------------------------------------------------------------- --------------------------- array 'examples' =>array 'log_level' => string '6135' (length=4) 1 => string 'intkey' (length=6) 'nullvalue' => string '' (length=0) 'truebool' => string '1' (length=1) 'falsebool' => string '' (length=0) 'intvalue' => string '-1' (length=2) 'floatvalue' => string '+1.4E-3' (length=7) 'stringvalue' => string 'Hello World' (length=11) 'quoted' => string 'Hello World' (length=11) 'apostrophed' => string ''Hello World'' (length=13) 'quoted escaped' => string 'it work's \fine\!' (length=17) 'apostrophed escaped' => string ''it work\'sfine' (length=15)--------------------------------------------------------------------------- ---------------------------
parse_ini_file('./foo.ini', true, INI_SCANNER_RAW)
);
array(1) {
["examples"]=>
array(11) {
[1]=>
string(40) "intkey "
["nullvalue"]=>
string(32) "null "
["truebool"]=>
string(33) "TRUE "
["falsebool"]=>
string(32) "false "
["intvalue"]=>
string(33) "-1 "
["floatvalue"]=>
string(31) "+1.4E-3 "
["stringvalue"]=>
string(30) "Hello World "
["quoted"]=>
string(35) ""Hello World" "
["apostrophed"]=>
string(30) "'Hello World' "
["quoted escaped"]=>
string(27) ""it work's \"fine\"!" "
["apostrophed escaped"]=>
string(22) "'it work\'s "fine"!' "
}
}
developer@mypse:~$ php -v PHP 5.2.4-2ubuntu5.12 with Suhosin-Patch 0.9.6.2 (cli) (built: Sep 20 2010 13:18:10) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologieswith Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans