解析 php 中的配置文件的算法(Doxygen 文件)
我有一个像这样的conf文件: http://pastie.org/768582 我的目标是进入一个数组,包含注释和每个键的键/值。
<代码> 大批( 数组(
'comment' => "The PROJECT_NAME tag is a single",
'key' => "PROJECT_NAME",
'value' => "JMK",
),
<代码>)
我想知道我必须使用什么算法?
我已经使用explode()函数将配置文件的内容转换为数组(逐行)。
现在我试图获取所有注释行,而下一行以“#”和一对键/值开头,但我在这里遇到了麻烦。
如果有人有想法那就太好了。谢谢。
I have a conf file like this: http://pastie.org/768582 and my goal is to get in an array the comments and the key/value of each keys.
array(
array(
'comment' => "The PROJECT_NAME tag is a single",
'key' => "PROJECT_NAME",
'value' => "JMK",
),
)
I would know what algoritm do I have to use?
I have already transform the content of the configuration file to an array (line by line) with explode() function.
Now I am trying to get all the comment lines while next line begins with '# ' and the couple key/value but it is here that I have trouble.
If someone have an idea it would be nice. Thx.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这将为您提供键/值对,但不会获得注释:
This will get you the key/value pairs, but not the comments:
这是一种
输出方式
here's one way
output
您可以尝试
parse_ini_file()
,格式看起来兼容。但它不会处理评论。You could try
parse_ini_file()
, the format looks compatible. It won't process the comments, though.