Joh*_*ski 6 php database settings file-io web-applications
我正在开发一个小应用程序,我可能想要/卖给别人.我想保留一些设置,并创建一个管理界面来修改它们.什么是最好的存储方式?对于我将拥有的10-20个设置,DB表似乎有点过分,我希望尽可能快地检索这些设置.平面文件是另一种可行的选择吗?使用平面文件有哪些陷阱?与存储多个键和值的平面文件交互的最快/最简单的方法是什么?
Pao*_*ino 15
我经常使用PHP来做parse_ini_file
这件事.
所以如果你用这个写一个.ini文件:
; This is a sample configuration file
; Comments start with ';', as in php.ini
[first_section]
one = 1
five = 5
animal = BIRD
[second_section]
path = "/usr/local/bin"
URL = "http://www.example.com/~username"
[third_section]
phpversion[] = "5.0"
phpversion[] = "5.1"
phpversion[] = "5.2"
phpversion[] = "5.3"
Run Code Online (Sandbox Code Playgroud)
并使用此PHP代码阅读:
define('BIRD', 'Dodo bird');
$ini_array = parse_ini_file("sample.ini", true);
print_r($ini_array);
Run Code Online (Sandbox Code Playgroud)
你会得到这个输出:
Array
(
[first_section] => Array
(
[one] => 1
[five] => 5
[animal] => Dodo bird
)
[second_section] => Array
(
[path] => /usr/local/bin
[URL] => http://www.example.com/~username
)
[third_section] => Array
(
[phpversion] => Array
(
[0] => 5.0
[1] => 5.1
[2] => 5.2
[3] => 5.3
)
)
)
Run Code Online (Sandbox Code Playgroud)