note 100851 added to function.parse-ini-file
| From: | daevid at daevid dot com | Date: | Thu, 11 Nov 2010 03:04:23 +0000 |
| Subject: | note 100851 added to function.parse-ini-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173934@lists.php.net to get a copy of this message | ||
Be warned that this function will not only NOT parse 'null', 'true',
'false', etc. but worse, it converts EVERYTHING to strings and sets 'true'
values to "1" and null/'false' values to "".
Here is my test.ini file:
[examples] ; this is a section
; this is a comment line
log_level = E_ALL & ~E_NOTICE
1 = 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 with
escaped 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)
verified with PHP 5.2.4 to 5.3.3
----
Server IP: 69.147.83.197
Probable Submitter: 206.169.197.253
----
Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php
Edit -- https://master.php.net/note/edit/100851
Del: integrated -- https://master.php.net/note/delete/100851/integrated
Del: useless -- https://master.php.net/note/delete/100851/useless
Del: bad code -- https://master.php.net/note/delete/100851/bad+code
Del: spam -- https://master.php.net/note/delete/100851/spam
Del: non-english -- https://master.php.net/note/delete/100851/non-english
Del: in docs -- https://master.php.net/note/delete/100851/in+docs
Del: other reasons-- https://master.php.net/note/delete/100851
Reject -- https://master.php.net/note/reject/100851
Search -- https://master.php.net/manage/user-notes.php