Hello,
Here's a patch again PHP_5_3 to add a parse_ini_string()
function.
It just works as parse_ini_file()
, except it accepts a string instead of
a filename, obviously.
We've been using for months a simple PHP function to do that, and while
I had to modify it to accept constants (as parse_ini_file()
does), I
thought it was time to use the core parsers instead of reinventing the
wheel.
I have the same patch available for 5.2, if anyone is interested.
Thank you for all the time and effort you put into PHP !
Olivier
Hi,
Hello,
Here's a patch again PHP_5_3 to add a
parse_ini_string()
function.
In general I think it's good to add that function, a few comments below.
+static
+ZEND_BEGIN_ARG_INFO_EX(arginfo_parse_ini_string, 0, 0, 1)
- ZEND_ARG_INFO(0, str)
If you come up with something might a bit more verbose (same below in
the prototype)
[..]
+/* {{{ proto array parse_ini_string(string str [, bool
process_sections [, int scanner_mode]])
- Parse configuration string */
+PHP_FUNCTION(parse_ini_string)
+{- char *string = NULL, *str = NULL;
- int str_len = 0;
please use tabs for indention, not spaces
- zend_bool process_sections = 0;
- long scanner_mode = ZEND_INI_SCANNER_NORMAL;
- zend_ini_parser_cb_t ini_parser_cb;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|bl",
&str, &str_len, &process_sections, &scanner_mode) == FAILURE) {RETURN_FALSE;
- }
- /* Set callback function */
- if (process_sections) {
BG(active_ini_file_section) = NULL;
ini_parser_cb = (zend_ini_parser_cb_t)
php_ini_parser_cb_with_sections;
- } else {
ini_parser_cb = (zend_ini_parser_cb_t)
php_simple_ini_parser_cb;
- }
- /* Setup string */
- string = (char *) emalloc(str_len + 1);
- strcpy(string, str);
- *(string + str_len + 1) = '\0';
Is that copy really needed? Where is the copy free'd?
If doing the copy please use strlcpy instead of strcpy. About strlcpy
see[1].
johannes
On Wednesday 05 November 2008 17:30:21 Olivier Grange-Labat wrote:
Hello,
Here's a patch again PHP_5_3 to add a
parse_ini_string()
function.It just works as
parse_ini_file()
, except it accepts a string instead of
a filename, obviously.We've been using for months a simple PHP function to do that, and while
I had to modify it to accept constants (asparse_ini_file()
does), I
thought it was time to use the core parsers instead of reinventing the
wheel.I have the same patch available for 5.2, if anyone is interested.
Thank you for all the time and effort you put into PHP !
Olivier
Hi,
Thanks, committed to 5.3 and HEAD :)
Regards,
Arnaud