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
Index: ext/standard/basic_functions.c
===
RCS file: /repository/php-src/ext/standard/basic_functions.c,v
retrieving revision 1.725.2.31.2.64.2.68
diff -u -r1.725.2.31.2.64.2.68 basic_functions.c
--- ext/standard/basic_functions.c 2 Nov 2008 21:19:37 -
1.725.2.31.2.64.2.68
+++ ext/standard/basic_functions.c 5 Nov 2008 15:42:37 -
@@ -989,6 +989,13 @@
ZEND_ARG_INFO(0, scanner_mode)
ZEND_END_ARG_INFO()
+static
+ZEND_BEGIN_ARG_INFO_EX(arginfo_parse_ini_string, 0, 0, 1)
+ZEND_ARG_INFO(0, str)
+ZEND_ARG_INFO(0, process_sections)
+ZEND_ARG_INFO(0, scanner_mode)
+ZEND_END_ARG_INFO()
+
#if ZEND_DEBUG
static
ZEND_BEGIN_ARG_INFO(arginfo_config_get_hash, 0)
@@ -3450,6 +3457,7 @@
PHP_FE(connection_status,
arginfo_connection_status)
PHP_FE(ignore_user_abort,
arginfo_ignore_user_abort)
PHP_FE(parse_ini_file,
arginfo_parse_ini_file)
+ PHP_FE(parse_ini_string,
arginfo_parse_ini_string)
#if ZEND_DEBUG
PHP_FE(config_get_hash,
arginfo_config_get_hash)
#endif
@@ -6372,6 +6380,42 @@
}
/* }}} */
+/* {{{ 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;
+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';
+
+array_init(return_value);
+if (zend_parse_ini_string(string, 0, scanner_mode, ini_parser_cb,
return_value TSRMLS_CC) == FAILURE) {
+zend_hash_destroy(Z_ARRVAL_P(return_value));
+efree(Z_ARRVAL_P(return_value));
+RETURN_FALSE;
+}
+}
+/* }}} */
+
#if ZEND_DEBUG
/* This function returns an array of ALL valid ini options with values and
* is not the same as ini_get_all() which returns only registered ini
options. Only useful for devs to debug php.ini scanner/parser! */
Index: ext/standard/basic_functions.h
===
RCS file: /repository/php-src/ext/standard/basic_functions.h,v
retrieving revision 1.139.2.4.2.6.2.9
diff -u -r1.139.2.4.2.6.2.9 basic_functions.h
--- ext/standard/basic_functions.h 15 Apr 2008 08:44:21 -
1.139.2.4.2.6.2.9
+++ ext/standard/basic_functions.h 5 Nov 2008 15:42:37 -
@@ -127,6 +127,7 @@
/* From the INI parser */
PHP_FUNCTION(parse_ini_file);
+PHP_FUNCTION(parse_ini_string);
#if ZEND_DEBUG
PHP_FUNCTION(config_get_hash);
#endif
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php