Introduction
An INI file is a simple text format for configuration, made of named sections of
key=value lines. It became familiar on Windows, where versions up to 3.1
kept system settings in files such as WIN.INI and SYSTEM.INI,
and programs kept their own. Windows 95 and Windows NT moved settings to the Registry,
and the file functions remain only for compatibility, but the layout is still everywhere
in other software, including php.ini.
There is no formal standard, so each program’s reader is slightly different. Many
configuration files with other extensions, including .cfg and
.conf files, use the same layout, as Python’s setup.cfg does.
Others with the same extensions have a different layout entirely.
Structure
An INI file is plain text, read line by line. Each line is one of these:
- a section header: a name in square brackets, as in
[server], which applies to the lines after it - a key and value:
name=value - a comment, starting with
;, or with#in many readers
Sections do not nest. Beyond that, readers disagree on whether key names are case-sensitive, whether spaces around the equals sign count, whether values can be quoted or continued on a later line, whether a comment can follow a value, how repeated keys are handled and which text encodings are understood. Values have no types of their own; each program decides what a value means.
Several formats use the same shape with stricter rules of their own. A
Windows Registry file looks like an INI file, with
key paths in square brackets and "name"=value lines, but has its own
header and value syntax and is read by Registry Editor, not the INI functions.
Internet shortcuts and
desktop entries are also written in this
style.
; Settings for the example program
[server]
host=example.org
port=8080
[logging]
level=info
file=C:\Logs\example.log
Links
Software
- Notepad – the text editor built into Windows (Windows)
- Notepad++ – free text editor with INI syntax colouring (Windows)
- Visual Studio Code – free code editor with built-in INI support (Windows, macOS, Linux)
Developers
- configparser – Python’s built-in reader and writer for INI-style files (Python)
- inih – small INI parser (C and C++)
- GetPrivateProfileString – the Windows function that reads INI files (C)
Reference
- INI file – Wikipedia’s comparison of the common variations
- The configuration file – PHP’s manual on
php.ini - git-config – Git’s manual, describing its own INI-style configuration files