From: Marcus Boerger Date: Wed, 12 Nov 2003 21:43:03 +0000 (+0000) Subject: Add helper function that splits inifile keys into an array which again X-Git-Tag: php-5.0.0b3RC1~711 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=daaef88047db285b4f1d6220651801d244e60312;p=php Add helper function that splits inifile keys into an array which again can be used in dba_fetch calls. --- diff --git a/ext/dba/dba.c b/ext/dba/dba.c index 7f04229e5b..31ce4827ef 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -66,6 +66,7 @@ function_entry dba_functions[] = { PHP_FE(dba_sync, NULL) PHP_FE(dba_handlers, NULL) PHP_FE(dba_list, NULL) + PHP_FE(dba_key_split, NULL) {NULL, NULL, NULL} }; /* }}} */ @@ -910,6 +911,27 @@ PHP_FUNCTION(dba_fetch) } /* }}} */ +/* {{{ proto array dba_key_split(string key) + Splits an inifile key into an array of the form array(0=>group,1=>value_name) */ +PHP_FUNCTION(dba_key_split) +{ + char *key, *name; + int key_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + return; + } + array_init(return_value); + if (key[0] == '[' && (name = strchr(key, ']')) != NULL) { + add_next_index_stringl(return_value, key+1, name - (key + 1), 1); + add_next_index_stringl(return_value, name+1, key_len - (name - key + 1), 1); + } else { + add_next_index_stringl(return_value, "", 0, 1); + add_next_index_stringl(return_value, key, key_len, 1); + } +} +/* }}} */ + /* {{{ proto string dba_firstkey(int handle) Resets the internal key pointer and returns the first key */ PHP_FUNCTION(dba_firstkey) diff --git a/ext/dba/php_dba.h b/ext/dba/php_dba.h index 08dadbdb2d..bc13ea62dc 100644 --- a/ext/dba/php_dba.h +++ b/ext/dba/php_dba.h @@ -138,6 +138,7 @@ PHP_FUNCTION(dba_optimize); PHP_FUNCTION(dba_sync); PHP_FUNCTION(dba_handlers); PHP_FUNCTION(dba_list); +PHP_FUNCTION(dba_key_split); #else #define dba_module_ptr NULL