*** post.c Thu Jul 8 13:20:22 1999 --- postjb.c Thu Jul 8 12:34:16 1999 *************** *** 552,559 **** --- 552,619 ---- #endif } + /* {{{ proto void parse_str(string str, [array output]) + Parses str as if it were the query string passed via an URL and sets variables in the current scope + If output array parameter given, puts the variables into that array. Array must be passed by reference. */ + void php3_parsestr(INTERNAL_FUNCTION_PARAMETERS) + { + pval *arg, *arrayArg; + char *res = NULL; + int argCount = ARG_COUNT(ht); + + if (argCount < 1 || argCount > 2 || getParameters(ht, argCount, &arg, &arrayArg) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_string(arg); + if (arg->value.str.val && *arg->value.str.val) { + res = estrndup(arg->value.str.val,arg->value.str.len); + } + + if(argCount == 1) + php3_treat_data(PARSE_STRING, res); + else + { + if (!ParameterPassedByReference(ht,2)) { + php3_error(E_WARNING, "Array not passed by reference in call to parse_str()"); + return; + } + + //Clean out array + pval_destructor(arrayArg _INLINE_TLS); + array_init(arrayArg); + + if(res) //hacked up version of php_treat_data + { + char *var, *val; + pval entry; + + entry.type = IS_STRING; + var = strtok(res, php3_ini.arg_separator); + + while (var) { + val = strchr(var, '='); + if (val) { /* have a value */ + *val++ = '\0'; + /* FIXME: XXX: not binary safe, discards returned length */ + _php3_urldecode(var, strlen(var)); + _php3_urldecode(val, strlen(val)); + + entry.value.str.val = estrdup(val); + entry.value.str.len = strlen(val); + + _php3_hash_update(arrayArg->value.ht, var, strlen(var)+1,&entry,sizeof(pval),NULL); + } + var = strtok(NULL, php3_ini.arg_separator); + } + efree(res); + } + } + } + /* {{{ proto void parse_str(string str) Parses str as if it were the query string passed via an URL and sets variables in the current scope */ + /* void php3_parsestr(INTERNAL_FUNCTION_PARAMETERS) { pval *arg; *************** *** 568,573 **** --- 628,634 ---- } php3_treat_data(PARSE_STRING, res); } + */ /* }}} */ /*