如何使用 PHP 读取和写入 ini 文件
我一直在浏览官方 php 文档,但找不到我要找的内容。
http://php.net/manual/en/function.parse-ini-file.php< /a>
我只想要一个函数来编辑和读取 php ini 文件中的值,例如,
[default_colors]
sitebg = #F8F8F8
footerbg = #F8F8F8
link = #F8F8F8
url = #F8F8F8
bg = #F8F8F8
text = #F8F8F8
border = #F8F8F8
lu_link = #F8F8F8
lu_url = #F8F8F8
lu_bg = #F8F8F8
lu_text = #f505f5
lu_border = #F8F8F8
- 如何读取属于“lu_link”或“footerbg”的值?
- 如何为这些地方写入新值?
I've been looking around the official php documentation but I'm unable to find what I'm looking for.
http://php.net/manual/en/function.parse-ini-file.php
I just want a function to edit and read the value from the php ini file, for instance,
[default_colors]
sitebg = #F8F8F8
footerbg = #F8F8F8
link = #F8F8F8
url = #F8F8F8
bg = #F8F8F8
text = #F8F8F8
border = #F8F8F8
lu_link = #F8F8F8
lu_url = #F8F8F8
lu_bg = #F8F8F8
lu_text = #f505f5
lu_border = #F8F8F8
- How do I read the value belonging to "lu_link" or "footerbg"?
- How to I write a new value for these places?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这个怎么样:
How about this:
下面是 PHP 目前缺少的
write_ini_file()
的实现,它将创建几乎相同的输入(注释除外):PHP_EOL
) 换行添加到部分之间。来源
示例输入
.ini
文件(取自 http://php.net/manual/en/function.parse-ini-file.php)用法示例:
<强>生成的
.ini
文件:Below is an implementation of
write_ini_file()
which PHP is currently lacking, it will create an almost identical (except comments) of the input:PHP_EOL
) new lines added between sections.Source
Example input
.ini
file (taken from http://php.net/manual/en/function.parse-ini-file.php)Example usage:
Resulting
.ini
file:这是一个函数版本,它创建一个可以写入文件的字符串。
Here's a functional version that creates a string that can be written to a file.
这是您使用类别选项读取和写入INI文件的函数!
如果您提供多维数组,您的 INI 文件中将包含类别。
或者基本数组将允许您快速读取和写入数据。
有关详细信息,请参阅下面的评论和示例:
Here is your function to read and write INI files with a category option!
If you provide multi dimensional array, you will have category in your INI file.
Or basic array will allow you to read and write data fast.
See the comments and example below for details:
您可以简单地将
parse_ini_file
与 PHP4/5 一起使用。这是文档: http://php.net/manual/en/ function.parse-ini-file.php
要将对象数组写回 ini 文件,请使用下面的非常快速的 & 方法。简单的解决方案:
You can simply use
parse_ini_file
with PHP4/5.Here is the doc: http://php.net/manual/en/function.parse-ini-file.php
To write back an array of objects back to the ini file, use below as a very fast & easy solution:
PEAR Config_Lite 包可以非常轻松地为您完成几乎所有工作(包括读取和写入)。在这里查看:http://pear.php.net/package/Config_Lite
The PEAR Config_Lite package can do almost all the work (both reading and writing) for you super-easily. Check it out here: http://pear.php.net/package/Config_Lite