Latest web development tutorials

PHP parse_ini_file () function

PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual

Definition and Usage

parse_ini_file () function parses a configuration file (ini file), and returns an array in which the settings.

grammar

parse_ini_file(file,process_sections)

参数 描述
file 必需。规定要检查的 ini 文件。
process_sections 可选。如果设置为 TRUE,则返回一个多维数组,包括了配置文件中每一节的名称和设置。默认是 FALSE。


Tips and Notes

Tip: This function can be used to read your own application's configuration files, nothing to do with the php.ini file.

Note: Some words can not be retained as an ini file keys, including: null, yes, no, true and false.The characters {} |! & ~ () "Nor can any place in the key name [.


Example 1

"Test.ini" Content:

[names]
me = Robert
you = Peter

[urls]
first = "http://www.example.com"
second = "http://www.w3cschool.cc"

PHP Code:

<?php
print_r(parse_ini_file("test.ini"));
?>

The code above will output:

Array
(
[me] => Robert
[you] => Peter
[first] => http://www.example.com
[second] => http://www.w3cschool.cc
)


Example 2

"Test.ini" Content:

[names]
me = Robert
you = Peter

[urls]
first = "http://www.example.com"
second = "http://www.w3cschool.cc"

PHP code (process_sections set to true):

<?php
print_r(parse_ini_file("test.ini",true));
?>

The code above will output:

Array
(
[names] => Array
(
[me] => Robert
[you] => Peter
)
[urls] => Array
(
[first] => http://www.example.com
[second] => http://www.w3cschool.cc
)
)


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual