LOADING STUFF...

PHP:parse_ini_file()的用法_Filesystem函数

技术教程3小时前发布 北陌
16 0 0

PHP:parse_ini_file()的用法_Filesystem函数

parse_ini_file

(PHP 4, PHP 5)

parse_ini_file — 解析一个配置文件

说明

array parse_ini_file
( string $filename
[, bool $process_sections = false
[, int $scanner_mode = INI_SCANNER_NORMAL
]] )

parse_ini_file() 载入一个由
filename 指定的 ini
文件,并将其中的设置作为一个联合数组返回。

ini 文件的结构和 php.ini 的相似。

参数

filename

要解析的 ini 文件的文件名。

process_sections

如果将最后的
process_sections 参数设为
TRUE,将得到一个多维数组,包括了配置文件中每一节的名称和设置。process_sections
的默认值是 FALSE

scanner_mode

Can either be INI_SCANNER_NORMAL (default) or
INI_SCANNER_RAW. If INI_SCANNER_RAW
is supplied, then option values will not be parsed.

返回值

成功时以关联数组 array 返回设置,失败时返回 FALSE

更新日志

版本
说明
5.3.0
Added optional scanner_mode parameter.
Single quotes may now be used around variable assignments.
Hash marks (#) may no longer be used as comments
and will throw a deprecation warning if used.
5.2.7
On syntax error this function will return FALSE rather than an empty
array.
5.2.4
由数字组成的键名和小节名会被 PHP 当作整数来处理,因此以
0 开头的数字会被当作八进制而以 0x 开头的会被当作十六进制。
5.0.0
该函数也开始处理选项值内的新行。
4.2.1
本函数也开始受到安全模式和
open_basedir 的影响。

范例

Example #1 sample.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”

Example #2 parse_ini_file() 例子

常量也可以在 ini
文件中被解析,因此如果在运行 parse_ini_file()
之前定义了常量作为 ini 的值,将会被集成到结果中去。只有 ini
的值会被求值。例如:

define(BIRD,

© 版权声明

相关文章

暂无评论

暂无评论...