PHP:使用file()将config.ini读入数组 [英] PHP: reading config.ini to array with file()
本文介绍了PHP:使用file()将config.ini读入数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
title = myTitle;
otherTitle = myOtherTitle;
当我用file()读取文件时,它会创建这个数组
[0] => title = myTitle;
[1] => otherTitle = myOtherTitle;
我想让数组看起来像是
[title] => myTitle;
[otherTitle] => myOtherTitle;
我使用错误的方法吗?我应该只读整个配置成一个刺,并从那里爆炸?
解决方案
您可以使用 parse_ini_file
功能。如果你的配置文件如下所示:
code> one = 1;
五= 5;
动物= BIRD;
函数将返回以下关联数组:
数组
(
[one] => 1
[five] => 5
[animal] => BIRD
)
My config file looks like this:
title = myTitle;
otherTitle = myOtherTitle;
when I read the file with file(), it creates this array
[0] => title = myTitle;
[1] => otherTitle = myOtherTitle;
and what I want the array to look like is
[title] => myTitle;
[otherTitle] => myOtherTitle;
Am I using the wrong approach her? Should i just read the entire config into a sting and explode it from there?
解决方案
You can use the parse_ini_file
function. It's available in PHP 4 and 5.
If your config file looks like this:
one = 1;
five = 5;
animal = BIRD;
The function will return the following associative array:
Array
(
[one] => 1
[five] => 5
[animal] => BIRD
)
这篇关于PHP:使用file()将config.ini读入数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文