parse_ini_string() - 解析配置字符串 - php 文件目录函数
parse_ini_string()
(PHP 5 >= 5.3.0, PHP 7)
解析配置字符串
说明
parse_ini_string(string $ini[,bool $process_sections= false[,int $scanner_mode= INI_SCANNER_NORMAL]]): arrayparse_ini_string()返回$ini字符串解析后的关联数组
ini 字符串的格式参考php.ini
参数
$iniini 字符串内容
$process_sections设置$process_sections参数为TRUE
,得到一个多维数组,包含名称和设置。$process_sections默认为FALSE
可以是INI_SCANNER_NORMAL
(默认)或INI_SCANNER_RAW
。如果是INI_SCANNER_RAW
,那么选项值不会被解析。
As of PHP 5.6.1 can also be specified asINI_SCANNER_TYPED
. In this mode boolean, null and integer types are preserved when possible. String values"true","on"and"yes"are converted toTRUE
."false","off","no"and"none"are consideredFALSE
."null"is converted toNULL
in typed mode. Also, all numeric strings are converted to integer type if it is possible.
返回值
执行成功返回一个关联数组,返回FALSE
为失败
注释
Note:保留关键字不能作为 ini 的键,包括 null, yes, no, true, false, on, off, none以及空值,off,no 和错误的结果集,值为 yes 和正确的结果集。除非使用INI_SCANNER_TYPED
模式。字符?{}|&~![()^"不能在任何地方使用作为键和有特殊意义的值。
参见
parse_ini_file()
解析一个配置文件
parse_ini_string_m is analog for a parse_ini_string function. had to code this function due to the lack of a php 5.3 on some hosting. parse_ini_string_m: - ignores commented lines that start with ";" or "#" - ignores broken lines that do not have "=" - supports array values and array value keys
With function parse_ini_stringM() below you can: - fix unvalued fields ('key' (invalid) ==> 'key=' (OK) ) - fix unquotted values with equal sign '=' ('key=value_part1=value_part2' ==> 'key="value_part1=value_part2"') - fix (solve) multidimensional arrays (makes 'key[key1][key2]=value' valid) function parse_ini_stringM() on github https://gist.github.com/msegu/c43a871c5a874a1d9bff978b448a0aa4 (here is too long) // Example: $ini = '[a] b c=d e='; var_export(parse_ini_string($ini, TRUE)); /* array ( 'a' => array ( 'c' => 'd', 'e' => '', ), ) */ $ini .= ' f[g][2]=h f[g][i]=j f[g][][]=k m=n=o'; var_export(parse_ini_string($ini, TRUE)); // false var_export(parse_ini_stringM($ini, TRUE)); /* array ( 'a' => array ( 'b' => '', 'c' => 'd', 'e' => '', 'f' => array ( 'g' => array ( 2 => 'h', 'i' => 'j', 3 => array ( 0 => 'k', ), ), ), 'm' => 'n=o', ), ) */
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!