diff options
author | Stanislav Malyshev <stas@php.net> | 2000-09-11 14:50:26 +0000 |
---|---|---|
committer | Stanislav Malyshev <stas@php.net> | 2000-09-11 14:50:26 +0000 |
commit | 1ccac6ed55a4d8cf93b38a1df56e640efa869da2 (patch) | |
tree | 63b37cc220b4ba2ad2459dfb62c7662efdc2a46c | |
parent | 5abacc5413420c4aae53a2e8a61feaf6387da2d2 (diff) | |
download | php-git-1ccac6ed55a4d8cf93b38a1df56e640efa869da2.tar.gz |
Add additional parameter to parse_str for saving result (thanks to
John Bafford <dshadow@zort.net>)
@ Added second parameter for parse_str to save result (John Bafford)
-rw-r--r-- | ext/standard/basic_functions.c | 2 | ||||
-rw-r--r-- | ext/standard/string.c | 37 | ||||
-rw-r--r-- | main/main.c | 6 | ||||
-rw-r--r-- | main/php_variables.c | 4 | ||||
-rw-r--r-- | main/php_variables.h | 2 |
5 files changed, 39 insertions, 12 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 7e50c73e9e..d047a59c75 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -182,7 +182,7 @@ function_entry basic_functions[] = { PHP_FE(levenshtein, NULL) PHP_FE(chr, NULL) PHP_FE(ord, NULL) - PHP_FE(parse_str, NULL) + PHP_FE(parse_str, second_arg_force_ref) PHP_FE(str_pad, NULL) PHP_FALIAS(rtrim, chop, NULL) PHP_FALIAS(strchr, strstr, NULL) diff --git a/ext/standard/string.c b/ext/standard/string.c index fc538b1f88..3465ef7975 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -775,6 +775,11 @@ PHP_FUNCTION(pathinfo) } } + if (opt == PHP_PATHINFO_DIRNAME || argc < 2) { + ret = php_basename(Z_STRVAL_PP(str), len); + add_assoc_string(tmp, "dirname", ret, 1); + } + if (argc == 2) { zval **element; zend_hash_get_current_data(Z_ARRVAL_P(tmp), (void **)&element); @@ -2397,23 +2402,45 @@ PHP_FUNCTION(setlocale) } /* }}} */ -/* {{{ proto void parse_str(string encoded_string) +/* {{{ proto void parse_str(string encoded_string, [array result]) Parses GET/POST/COOKIE data and sets global variables */ PHP_FUNCTION(parse_str) { zval **arg; + zval **arrayArg; + zval *sarg; char *res = NULL; + int argCount; + PLS_FETCH(); SLS_FETCH(); - if (zend_get_parameters_ex(1, &arg) == FAILURE) { + argCount = ARG_COUNT(ht); + if(argCount < 1 || argCount > 2 || zend_get_parameters_ex(argCount, &arg, &arrayArg) == FAILURE) { WRONG_PARAM_COUNT; } + convert_to_string_ex(arg); - if ((*arg)->value.str.val && *(*arg)->value.str.val) { - res = estrndup((*arg)->value.str.val,(*arg)->value.str.len); + sarg = *arg; + if (sarg->value.str.val && *sarg->value.str.val) { + res = estrndup(sarg->value.str.val, sarg->value.str.len); + } + + if(argCount == 1) + php_treat_data(PARSE_STRING, res, NULL ELS_CC PLS_CC SLS_CC); + else + { + if(!ParameterPassedByReference(ht, 2)){ + php_error(E_WARNING, "Array not passed by reference in call to parse_str()"); + return; + } + + /* Clear out the array that was passed in. */ + zval_dtor(*arrayArg); + array_init(*arrayArg); + + php_treat_data(PARSE_STRING, res, *arrayArg ELS_CC PLS_CC SLS_CC); } - php_treat_data(PARSE_STRING, res ELS_CC PLS_CC SLS_CC); } /* }}} */ diff --git a/main/main.c b/main/main.c index bbb2a9174d..7b4a8ec0c9 100644 --- a/main/main.c +++ b/main/main.c @@ -1007,21 +1007,21 @@ static int php_hash_environment(ELS_D SLS_DC PLS_DC) case 'p': case 'P': if (!_gpc_flags[0] && !SG(headers_sent) && SG(request_info).request_method && !strcasecmp(SG(request_info).request_method, "POST")) { - php_treat_data(PARSE_POST, NULL ELS_CC PLS_CC SLS_CC); /* POST Data */ + php_treat_data(PARSE_POST, NULL, NULL ELS_CC PLS_CC SLS_CC); /* POST Data */ _gpc_flags[0]=1; } break; case 'c': case 'C': if (!_gpc_flags[1]) { - php_treat_data(PARSE_COOKIE, NULL ELS_CC PLS_CC SLS_CC); /* Cookie Data */ + php_treat_data(PARSE_COOKIE, NULL, NULL ELS_CC PLS_CC SLS_CC); /* Cookie Data */ _gpc_flags[1]=1; } break; case 'g': case 'G': if (!_gpc_flags[2]) { - php_treat_data(PARSE_GET, NULL ELS_CC PLS_CC SLS_CC); /* GET Data */ + php_treat_data(PARSE_GET, NULL, NULL ELS_CC PLS_CC SLS_CC); /* GET Data */ _gpc_flags[2]=1; } break; diff --git a/main/php_variables.c b/main/php_variables.c index 65baee6248..4187d00eba 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -209,7 +209,7 @@ SAPI_POST_HANDLER_FUNC(php_std_post_handler) } -void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC) +void php_treat_data(int arg, char *str, zval* destArray ELS_DC PLS_DC SLS_DC) { char *res = NULL, *var, *val; pval *array_ptr; @@ -236,7 +236,7 @@ void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC) } break; default: - array_ptr=NULL; + array_ptr=destArray; break; } diff --git a/main/php_variables.h b/main/php_variables.h index ad65a089cf..f71fe2762b 100644 --- a/main/php_variables.h +++ b/main/php_variables.h @@ -30,7 +30,7 @@ #define PARSE_COOKIE 2 #define PARSE_STRING 3 -void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC); +void php_treat_data(int arg, char *str, zval* destArray ELS_DC PLS_DC SLS_DC); void php_import_environment_variables(ELS_D PLS_DC); PHPAPI void php_register_variable(char *var, char *val, pval *track_vars_array ELS_DC PLS_DC); PHPAPI void php_register_variable_ex(char *var, zval *val, pval *track_vars_array ELS_DC PLS_DC); |