开发者

How can I make/patch php source (c code) to read an array from php.ini?

开发者 https://www.devze.com 2023-02-07 07:47 出处:网络
I\'m experienced with 开发者_StackOverflow社区php but I\'m a novice to the php source and php extensions. I want to extend php so that it randomly chooses an upload_tmp_dir from an array, rather than

I'm experienced with 开发者_StackOverflow社区php but I'm a novice to the php source and php extensions. I want to extend php so that it randomly chooses an upload_tmp_dir from an array, rather than one fixed dir.

It doesn't look like php and the ini-file reading code has any natural ability to parse arrays in the ini file.

Is there any existing code or extension (either in the tree or outside it) that allows for mapping an ini-defined array to a global array val in php?

Otherwise I guess I'll introduce ini vals like "num_upload_dirs" and then "upload_tmp_dir_1" and "upload_tmp_dir_2" etc. and then explicitly check for all vals.

OR write the line-parsing and global-array-creating routines myself into the ini-file reader. Neither are very appealing. Any other suggestions?


The ini file format doesn't support arrays.

You will be best served by doing uplaod_tmp_dir_1 etc. You get no benefit from using array syntax.

It is actually fewer bytes if you think about it. ;)


PHP supports arrays in ini files by default. There is no need to patch anything

The ini

key[] = value1
key[] = value2

with this php

var_dump(parse_ini_file('my.ini'));

returns

array(1) {
  ["key"]=>
  array(2) {
    [0]=>
    string(6) "value1"
    [1]=>
    string(6) "value2"
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消