PHPのparse_ini_file()関数
定義と使用法
parse_ini_file()関数は、設定ファイル(iniファイル)を解析し、アレイの設定を返します。
文法
parse_ini_file(file,process_sections)
参数 | 描述 |
---|---|
file | 必需。规定要检查的 ini 文件。 |
process_sections | 可选。如果设置为 TRUE,则返回一个多维数组,包括了配置文件中每一节的名称和设置。默认是 FALSE。 |
ヒントと注意事項
ヒント:この関数は、php.iniファイルには何も、独自のアプリケーションの設定ファイルを読み込むために使用することはできません。
注:ヌル、はい、いいえ、真と偽:いくつかの単語を含むiniファイルキー、として保持することはできません。文字{} |!&〜()」もキー名の[内の任意の場所にすることができます。
例1
「Test.ini「コンテンツ:
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "http://www.w3cschool.cc"
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "http://www.w3cschool.cc"
PHPコード:
<?php
print_r(parse_ini_file("test.ini"));
?>
print_r(parse_ini_file("test.ini"));
?>
意志出力上のコード:
Array
(
[me] => Robert
[you] => Peter
[first] => http://www.example.com
[second] => http://www.w3cschool.cc
)
(
[me] => Robert
[you] => Peter
[first] => http://www.example.com
[second] => http://www.w3cschool.cc
)
例2
「Test.ini「コンテンツ:
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "http://www.w3cschool.cc"
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "http://www.w3cschool.cc"
PHPコード(trueに設定のprocess_sections):
<?php
print_r(parse_ini_file("test.ini",true));
?>
print_r(parse_ini_file("test.ini",true));
?>
意志出力上のコード:
Array
(
[names] => Array
(
[me] => Robert
[you] => Peter
)
[urls] => Array
(
[first] => http://www.example.com
[second] => http://www.w3cschool.cc
)
)
(
[names] => Array
(
[me] => Robert
[you] => Peter
)
[urls] => Array
(
[first] => http://www.example.com
[second] => http://www.w3cschool.cc
)
)
PHPファイルシステムリファレンスマニュアルを完了