PHP 中的 parse_ini_file() 函数
phpprogrammingserver side programming更新于 2025/8/9 17:07:17
parse_ini_file() 函数用于解析配置文件 (ini)
语法
parse_ini_file(file_path, process_sections)
参数
file_path − 需要解析的 ini 文件。
process_sections − 如果设置为 TRUE,您将获得一个包含部分名称和设置的多维数组。
返回
parse_ini_file() 函数成功时将以关联数组的形式返回设置。失败时返回 FALSE。
假设我们的 “demo.ini” 内容是 −
[names] one = Anne two = Katie three = Tom [urls] host1 = "https://www.example1.com" host2 = "https://www.example2.com"
示例
<?php
print_r(parse_ini_file("demo.ini"));
?>
输出
Array ( [one] => Anne [two] => Katie [three] => Tom [host1] => https://www.example1.com [host2] => https://www.example2.com )

