Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Official ZPE/YASS documentationini_decode

ini_decode (string data) ⇒ map

Parses a string in the INI format to a map. The resulting map may contain additional maps inside it representing groups of values. For more information see https://en.wikipedia.org/wiki/INI_file.

First available: Version 1.13.1

Notes

The INI parser does not translate data to appropriate data types, it leaves everything as string values. For each value, it is very easy to cast data to the correct data type.

The INI parser will parse comments, but will ignore them and they will not be included in the final output.

If there are no groups, the output will be put into the final map. Additionally, if properties are stated before a group is stated, they will be in the top level map.

Take the following example:

INI file
#Application configuration

app_name = My App

;General data
[General]
version = 1.0.0
build = 95

;User settings
[UserSettings]
theme = dark
font_size = 12

;Network settings
[Network]
host = 192.168.1.1
port = 8080

On lines 1, 5, 10 and 15 there are comments. These are ignored.

On line 3, there is a property (app_name) that has no group. This is added to the main map. Thus, the final output for this would look like:

[
  "app_name" => "My App",
  "UserSettings" => [
   "font_size" => "12",
   "theme" => "dark"
  ],
  "Network" => [
   "port" => "8080",
   "host" => "192.168.1.1"
  ],
  "General" => [
   "build" => "95",
   "version" => "1.0.0"
  ]
]
Comments
Feedback 👍
Comments are sent via email to me.