[英]How can I parse a .ini file using php?
I've joined to a new team/project and there is a .ini
file in the project which is used as the project configuration file. 我加入了一个新的团队/项目,并且该项目中有一个
.ini
文件,该文件用作项目配置文件。 The content of it looks like: 它的内容如下:
[version]
v = 1
[paths]
website = http://localhost
base_url = /myweb/
images_path = C:\\xampp\\htdocs\\myweb\\img\\
attached_file_path = C:\\xampp\\htdocs\\myweb\\attached_files\\
[limitation values]
max_avatar_size = 2 ; MB
max_uploaded_image_size = 3 ; MB
max_uploaded_file_size = 4 ; MB
I can access those values like this: config('item_name')
, ie config('base_url')
which return /myweb/
. 我可以访问以下值:
config('item_name')
,即config('base_url')
,它返回/myweb/
。 Noted that config()
function uses parse_ini_file()
function. 注意,
config()
函数使用parse_ini_file()
函数。
My question is, what are those section titles? 我的问题是,这些部分的标题是什么? ie
[version]
, [paths]
.. ? 即
[version]
, [paths]
..? Are they accessible? 他们可以到达吗? If yes, how?
如果是,怎么办?
The function parse_ini_file()
have a second argument : bool process_sections
. 函数
parse_ini_file()
具有第二个参数: bool process_sections
。
$ini_array = parse_ini_file("sample.ini", true); // true means "process_sections"
// var_dump(array_keys($ini_array)) ;
var_dump($ini_array['paths']['base_url']) ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.