PHP parse_ini_file() 函数
❮ PHP 文件系统参考示例
"test.ini" 的内容
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "https://w3schools.org.cn"
PHP 代码
<?php
print_r(parse_ini_file("test.ini"));
?>
上面代码的输出将是
Array (
[me] => Robert
[you] => Peter
[first] => http://www.example.com
[second] => https://w3schools.org.cn
)
定义和用法
parse_ini_file() 函数解析配置文件 (ini) 并返回设置。
提示: 此函数可用于读取您自己的配置文件,与 php.ini 文件无关。
注意: 以下保留字不得用作 ini 文件的键:null, yes, no, true, false, on, off, none。此外,以下保留字符不得用于键中:{}|&~!()^"。
语法
parse_ini_file(file, process_sections, scanner_mode)
参数值
参数 | 描述 |
---|---|
file | 必需。指定要解析的 ini 文件 |
process_sections | 可选。如果设置为 TRUE,则返回一个包含节名称和设置的多维数组。默认为 FALSE |
scanner_mode |
可选。可以是以下值之一
|
技术详情
返回值 | 成功时返回数组,失败时返回 FALSE |
---|---|
PHP 版本 | 4.0+ |
PHP 更新日志 | PHP 7.0:哈希符号 (#) 不再被识别为注释 PHP 5.6.1:添加了 INI_SCANNER_TYPED 模式 PHP 5.3:添加了可选的 scanner_mode 参数 |
更多示例
示例
"test.ini" 的内容
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "https://w3schools.org.cn"
PHP 代码(将 process_sections 设置为 true)
<?php
print_r(parse_ini_file("test.ini",true));
?>
上面代码的输出将是
数组
(
[names] => Array
(
[me] => Robert
[you] => Peter
)
[urls] => Array
(
[first] => http://www.example.com
[second] => https://w3schools.org.cn
)
)
❮ PHP 文件系统参考