array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.parse-ini-string.php', 1 => 'parse_ini_string', ), 'up' => array ( 0 => 'ref.filesystem.php', 1 => '文件系统函数', ), 'prev' => array ( 0 => 'function.parse-ini-file.php', 1 => 'parse_ini_file', ), 'next' => array ( 0 => 'function.pathinfo.php', 1 => 'pathinfo', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/filesystem/functions/parse-ini-string.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
parse_ini_string — 解析配置字符串
$ini_string
, bool $process_sections
= false
, int $scanner_mode
= INI_SCANNER_NORMAL
): array|false
parse_ini_string() 返回 ini_string
字符串解析后的关联数组。
ini 字符串的格式参考 php.ini
ini_string
ini 字符串内容。
process_sections
设置 process_sections
参数为 true
,得到一个多维数组,包含名称和设置。process_sections
默认为 false
。
scanner_mode
可以是 INI_SCANNER_NORMAL
(默认)或 INI_SCANNER_RAW
。如果是 INI_SCANNER_RAW
,那么选项值不会被解析。
As of PHP 5.6.1 can also be specified as INI_SCANNER_TYPED
.
In this mode boolean, null and integer types are preserved when possible.
String values "true"
, "on"
and "yes"
are converted to true
. "false"
, "off"
, "no"
and "none"
are considered false
. "null"
is converted to null
in typed mode. Also, all numeric strings are converted to integer type if it is possible.
执行成功返回一个关联数组,返回 false
为失败。
注意: 有些保留字不能作为 ini 文件中的键名,包括:
null
、yes
、no
、true
、false
、on
、off
、none
。除非使用INI_SCANNER_TYPED
模式,否则null
、off
、no
和false
的值等效于""
,on
、yes
和true
的值等效于"1"
。字符?{}|&~![()^"
也不能用在键名的任何地方,而且这些字符在选项值中有着特殊的意义。