You are here: C97net • 5.11 Misc Functions
Read configuration from INI-styled contents
function parse_ini_str ($Str, $ProcessSections = TRUE)
While PHP already provides a simple way to read an INI file using parse_ini_file () function, it doesn't have a way to read INI from a variable.
$Str = the string containing INI configuration.
$ProcessSections = set to TRUE to get a multidimensional array, with the section names and settings included.
This function is required by qE's module management.
It returns an array of configuration.
Example 1
<?php
require './includes/user_init.php';
// taken from PHP documentation
$ini_var = "; This is a sample configuration file
; Comments start with ';', as in php.ini
[first_section]
one = 1
five = 5
animal = BIRD
[second_section]
path = \"/usr/local/bin\"
URL = \"http://www.example.com/~username\"";
// Parse without sections
print_r (parse_ini_str ($ini_var, false));
// Parse with sections
print_r (parse_ini_str ($ini_var, false));
?>
Sample Output
Array
(
[one] => 1
[five] => 5
[animal] => BIRD
[path] => /usr/local/bin
[URL] => http://www.example.com/~username
)
Array
(
[one] => 1
[five] => 5
[animal] => BIRD
[path] => /usr/local/bin
[URL] => http://www.example.com/~username
)
Notice that unlike PHP's parse_ini_file (), this function doesn't return contants.
There is no comment. Why not be the first?