print

parse_ini_str ()

You are here: C97net5.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.

Posted on: Aug-27-2010 at 07:00am
Last Updated: Jan-01-1970 at 07:00am

There is no comment. Why not be the first?

read more More Comments/Post Your Own

Account

Search

Tags

acp add all also any create default display don download easy echo etc features field file files folder form function includes information init kemana link list may module name need number own page php please qengine read require script set site skin time tpl url use user using version welcome