不用担心,解析.ini
文件是一种标准方法。(请参阅PHP文档中的parse_ini_file)。
使用您的文件作为本示例的基础:
[STRINGS]
mystring = fooooo
value = foo_bar
$ini_array = parse_ini_file("myini.ini");
print_r($ini_array); # prints the entire parsed .ini file
print($ini_array['mystring']); #prints "fooooo"
请注意,默认情况下,将parse_ini_file
忽略所有ini设置的节并将其合并到同一对象中。如果你想拥有的东西分段作用域为你的Python例如,通过true
对process_sections
参数(第二个参数)。
$ini_array = parse_ini_file("myini.ini", true /* will scope sectionally */);
print($ini_array['mystring']); #prints nothing
print($ini_array['STRINGS']['mystring']); #prints fooooo