]> granicus.if.org Git - php/commitdiff
Add helper function that splits inifile keys into an array which again
authorMarcus Boerger <helly@php.net>
Wed, 12 Nov 2003 21:43:03 +0000 (21:43 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 12 Nov 2003 21:43:03 +0000 (21:43 +0000)
can be used in dba_fetch calls.

ext/dba/dba.c
ext/dba/php_dba.h

index 7f04229e5b7a995bbb6a4a99b736b73f4c024e61..31ce4827ef72fd28b5327ba7dc62ec7d4b5c998d 100644 (file)
@@ -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)
index 08dadbdb2dc27ed1f1419ada23f5fa99d19167ca..bc13ea62dca2722c116174cf2302f8d739ba8e26 100644 (file)
@@ -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