PHPIni (.ini)
PHPIni (.ini)
Background & Context
-
- Configuration file format.
- Associates keys to values.
- Gathers elements into sections.
- Can represent PHP expressions such as arrays or maps.
- Configuration format for PHP application servers.
- Plain text format.
Import & Export
- Import["file","PHPIni"] returns a representation of a file as an Association.
- Import["file",{"Ini",elem}] returns the specified data representation of a file.
- Export["file.ini",expr] exports expr as an Ini file.
- See the following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
Import Elements
- General Import elements:
-
"Elements" list of elements and options available in this file "Summary" summary of the file "Rules" list of rules for all available elements - Data representation elements:
-
"Data" data as an association "DataRules" data as a list of rules "CommentedData" data as a list of sections as rules, comments as strings, and values as associations - The "PHPIni" format exports elements of an association or a list.
- "PHPIni" treats an association as a list of sections. The keys specify the section names; the values specify the elements of a section as associations.
- Lists in the Wolfram Language are represented in PHPIni as PHP arrays.
- Associations in the Wolfram Language are represented in PHPIni as PHP maps.
- The PHP symbols "On", "True" and "Yes" are imported as True. The PHP symbols "Off", "False" and "No" are imported as False.
- "PHPIni" accepts lists containing a mixture of rules and strings. Rules are exported as sections; strings are exported as commented lines.
- A commented line starts with ";".
- Elements declared before the first section are associated with the key None.
- "CommentedData" preserves inline comments; other data representations discard them.
Examples
Basic Examples (9)
Export an association as a section with properties:
ExportString[<|"PHP" -> <|"max_execution_time" -> 30, "max_input_time" -> 60, "memory_limit" -> "128M"|>|>, "PHPIni"]file = CreateFile[];Add a section and an element to it:
WriteString[
file, "
[PHP]
engine = On
"];Import[file, "PHPIni"]file = CreateFile[];Write properties and comments to it:
WriteString[file, "
[PHP]
; ...
[PDO]
pdo_mysql.default_socket = /path/to/mysql.sock
[PostgresSQL]
; Allow or prevent persistent links.
pgsql.allow_persistent = On ; On | Off
"];Import the data only, as an Association:
Import[file, "PHPIni"]Import the data and the commented lines:
Import[file, {"PHPIni", "CommentedData"}]If no section was defined, elements are associated to the key None:
ImportString["global_key = global_value ", "PHPIni"]PHPIni represents lists as a PHP array:
ExportString[<|"MyApp" -> <|"SpecialDays" -> {"Monday", "Tuesday", "Friday"}|>|>, "PHPIni"]PHPIni represents associations as a PHP map:
ExportString[<|"MyApp" -> <|"db_config" -> <|"User" -> "root", "host" -> "localhost", "port" -> "5678"|>|>|>, "PHPIni"]Sections must start with the character "[" and finish with "]":
ImportString[" [section]", "PHPIni"]Commented lines must start with the character ";":
ImportString[" ; comments", "PHPIni"]TakeDrop[{1, 2, 3, 4}, 2]Arbitrary expressions are converted to strings:
ExportString[<|"GeoData" -> <|"default_position" -> GeoPosition[Entity["City", {"Paris", "IleDeFrance", "France"}]]|>|>, "PHPIni"]It is possible to build a PHPIni configuration file with commented elements:
ExportString[{None -> {"", " This file is a PHPIni configuration file.", ""}, "section1" -> {"key1" -> <|"Value" -> "element1 ", "Comment" -> " this is the first element"|>}}, "PHPIni"]Related Guides
History
Introduced in 2017 (11.1)