And way cool would be array support:key9 = [ 1, 2, 3 ]And globals and superglobals:key10 = $Many people make their own INI parsers - I have a few versions - I think I'll try supporting the operators and arrays...BUT, a "post parser" can convert such values as key9's and these:key8a = '($ * 2) Not mentioned in the documentation, this function acts like include:"Files are included based on the file path given or, if none is given, the include_path specified.^ | & ~ - ; = within a string need to be quoted, with either double- or single-quotes. Also, the concatenation operation is built-in:key7 = "foo" 'bar' PHP_VERSION $That result will have spaces before the constant and variable but not between the two quoted words.This eliminates the spaces:key7a = "foo" 'bar'PHP_VERSION$But, punctuation fools the parsing:key7b = "foo" 'bar', PHP_VERSION-$That needs to be (with spaces):key7c = "foo" 'bar', PHP_VERSION - $Or (without spaces):key7d = "foo" 'bar,'PHP_VERSION'-'$And, of course, leading and trailing spaces in values are trimmed. It would be cool for PHP to support shift and arithmetic operators:key8 = ($ * 2) 1And cooler still, all logical operators; perhaps also comparison operators and the execution operator.' ; this is a apostrophed string with escaped apostrophes valid special cases ; this is a section with square brackets and whitespaces at the beginningquoted multiline = "line1line2line3" ; this is a quoted multiline stringapostrophed multiline = "line1line2line3" ; this is a apostrophed multiline string spaces before key = is ok ; this line has whitespaces at the beginningno val = ; this setting has no key= no key ; this setting has no value= ; this setting has no key and no value[bad cases] ; you should never do that but it worksnotgood = unquoted"string ; this value has a single quotenotgood2 = unapostrophed'string ; this value has a single apostrophebad = "unclosed quotes ; this value has unclosed quotesbad2 = 'unclosed apostrophes ; this value has unclosed apostrophes[invalidsection]invalid setting files or JSON file format as it is also known as, are very useful format to store stuff in. Strangely enough there is this nice function to read the file, but no function to write it. Use it as: put_ini_file(string $file, array $array) Warning: parse_ini_files cannot cope with values containing the equal sign (=).
The following function supports sections, comments, arrays, and key-value pairs outside of any section.
if your application is widely used), the webserver might return it as plain text.]]
Here's a little function to match this, using dots (customizable)./*[normal]foo = bar; use quotes to keep your key as it is'dots' = true[array]foo = 1foo = 2[dictionary]foo[debug] = falsefoo[path] = /some/path[multi]config.debug = password = 123456*/ Working on a project for a client recently, I needed a way to set a default configuration INI file, but also wanted to allow the client to override the settings through the use of a custom INI file.; This is a sample configuration file ; Comments start with ';', as in [first_section] one = 1 five = 5 animal = BIRD [second_section] path = "/usr/local/bin" URL = " [third_section] phpversion = "5.0" phpversion = "5.1" phpversion = "5.2" phpversion = "5.3" urls[svn] = " urls[git] = " /*[base]host=localhostuser=testuserpass=testpassdatabase=default[users:base]host=localhostuser=testuserpass=testpassdatabase=users[archive : base]host=localhostuser=testuserpass=testpassdatabase=archive*/ If your configuration file holds any sensitive information (such as database login details), remember NOT to place it within your document root folder!A common mistake is to replace php files, which are formatted in PHP: With files which are written in plain text:[database]host = localhost The file can be read by anyone who knows where it's located, if it's under your document root folder. To those who were like me looking if this could be used to create an array out of commandline output I offer you the function below (I used it to parse mplayer output).Beware that similar keys will overwrite one another (unless in different sections)./*; Commented line start with ';'global_value1 = a string valueglobal_value1 = another string value; empty lines are discarded[Section1]key = value; whitespace around keys and values is discarded toootherkey=other valueotherkey=yet another value; this key-value pair will overwrite the former.*/ I found that this function will not work on remote files.I tried $some Array = parse_ini_file(" and it reports Cannot Open ' for reading ...