Join Up!
96815 members and counting!

 
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links 
search for in the  
previousmove_uploaded_filepathinfonext
Last updated: Sun, 27 Oct 2002
view the printer friendly version or the printer friendly version with notes or change language to Finnish | German | Spanish

parse_ini_file

(PHP 4 )

parse_ini_file -- Parse a configuration file

Description

array parse_ini_file ( string filename [, bool process_sections])

parse_ini_file() loads in the ini file specified in filename, and returns the settings in it in an associative array. By setting the last process_sections parameter to TRUE, you get a multidimensional array, with the section names and settings included. The default for process_sections is FALSE

Poznámka: This function has nothing to do with the php.ini file. It is already processed, the time you run your script. This function can be used to read in your own application's configuration files.

Poznámka: If a value in the ini file contains any non-alphanumeric characters it needs to be enclosed in double-quotes (").

Poznámka: Since PHP 4.2.1 this function is also affected by safe_mode and open_basedir.

The structure of the ini file is similar to that of the php.ini's.

Varování

If the ini file you are trying to parse is malformed, PHP will exit.

Příklad 1. Contents of sample.ini

; This is a sample configuration file
; Comments start with ';', as in php.ini

[first_section]
one = 1
five = 5

[second_section]
path = /usr/local/bin
URL = "http://www.example.com/~username"

Příklad 2. parse_ini_file() example

<?php

// Parse without sections
$ini_array = parse_ini_file("sample.ini");
print_r($ini_array);

// Parse with sections
$ini_array = parse_ini_file("sample.ini", TRUE);
print_r($ini_array);

?>

Would produce:

Array
(
    [one] => 1
    [five] => 5
    [path] => /usr/local/bin
    [URL] => http://www.example.com/~username
)
Array
(
    [first_section] => Array
        (
            [one] => 1
            [five] => 5
        )

    [second_section] => Array
        (
            [path] => /usr/local/bin
            [URL] => http://www.example.com/~username
        )

)

User Contributed Notes
parse_ini_file
add a note about notes
There are no user contributed notes for this page.
previousmove_uploaded_filepathinfonext
Last updated: Sun, 27 Oct 2002
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by: http://phpbuilder.com/
Last updated: Thu Oct 31 18:34:28 2002 EST