Re: PHP 4.0 Bug #5768: patch to make parse_str() optionally save into an array
| From: | Derick Rethans | Date: | Sat, 05 Aug 2000 13:53:13 +0000 |
| Subject: | Re: PHP 4.0 Bug #5768: patch to make parse_str() optionally save into an array | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-27831@lists.php.net to get a copy of this message | ||
Hello,
if nobody objects, I'm willing to add it into cvs, but please send in an unified diff (diff
-u).
Derick
dshadow@zort.net wrote:
> From: dshadow@zort.net
> Operating system: Linux
> PHP version: 4.0.1pl2
> PHP Bug Type: Feature/Change Request
> Bug description: patch to make parse_str() optionally save into an array
>
> The following patch modifies parse_str() to optionally save variables into an array, rather
> than into the current variable space.
>
> Usage:
>
> Normal:
> parse_str(encodedString);
>
> Saves variables into the output array, rather than into the current variable space:
> parse_str(encodedString, outputArray);
>
> This has been used in a production environment for at least six months with no problems. (The
> patch was originally written for PHP3.) I'm hoping this can get included with PHP so I
> don't have to keep repatching whenever a new PHP version is released.
>
> John Bafford
> dshadow@zort.net
>
> --
>
> *** string.old Mon Jul 24 17:14:32 2000
> --- string.c Mon Jul 24 17:16:23 2000
> ***************
> *** 2162,2184 ****
> }
> /* }}} */
>
> ! /* {{{ proto void parse_str(string encoded_string)
> ! Parses GET/POST/COOKIE data and sets global variables. */
> PHP_FUNCTION(parse_str)
> {
> ! zval **arg;
> char *res = NULL;
> PLS_FETCH();
> SLS_FETCH();
> !
> ! if (zend_get_parameters_ex(1, &arg) == 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);
> }
> ! php_treat_data(PARSE_STRING, res ELS_CC PLS_CC SLS_CC);
> }
> /* }}} */
>
> --- 2162,2227 ----
> }
> /* }}} */
>
> ! /* {{{ proto void parse_str(string encoded_string, [array storage])
> ! Parses GET/POST/COOKIE data and sets global variables.
> ! Stores into storage if array is given
> ! */
> PHP_FUNCTION(parse_str)
> {
> ! zval **arg, **arrayArg;
> ! zval *sarg;
> char *res = NULL;
> + int argCount;
> +
> PLS_FETCH();
> SLS_FETCH();
> !
> ! 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);
> ! 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 ELS_CC PLS_CC SLS_CC);
> ! else
> ! {
> ! if(!ParameterPassedByReference(ht, 2)){
> ! php3_error(E_WARNING, "Array not passed by reference in call to
> parse_str()");
> ! return;
> ! }
> !
> ! //Clear out the array that was passed in
> ! pval_destructor(*arrayArg);
> ! array_init(*arrayArg);
> !
> ! if(res) //hacked up php_treat_data
> ! {
> ! char *var, *val;
> !
> ! var = strtok(res, PG(arg_separator));
> !
> ! while (var) {
> ! val = strchr(var, '=');
> ! if (val) { /* have a value */
> ! *val++ = '\0';
> ! /* FIXME: XXX: not binary safe, discards returned
> length */
> ! php_url_decode(var, strlen(var));
> ! php_url_decode(val, strlen(val));
> !
> ! add_assoc_string(*arrayArg, var, val, 1);
> ! }
> ! var = strtok(NULL, PG(arg_separator));
> ! }
> ! }
> ! }
> !
> ! efree(res);
> }
> /* }}} */
>
> *** basic_functions.old Mon Jul 24 17:20:49 2000
> --- basic_functions.c Mon Jul 24 17:20:51 2000
> ***************
> *** 169,175 ****
> PHP_FE(levenshtein,
> NULL)
> PHP_FE(chr,
> NULL)
> PHP_FE(ord,
> NULL)
> ! PHP_FE(parse_str, NULL)
> PHP_FE(str_pad, NULL)
> PHP_FALIAS(rtrim, chop, NULL)
> PHP_FALIAS(strchr, strstr, NULL)
> --- 169,175 ----
> PHP_FE(levenshtein,
> NULL)
> PHP_FE(chr,
> NULL)
> PHP_FE(ord,
> NULL)
> ! PHP_FE(parse_str,
> second_arg_force_ref)
> PHP_FE(str_pad, NULL)
> PHP_FALIAS(rtrim, chop, NULL)
> PHP_FALIAS(strchr, strstr, NULL)
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: php-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
Derick Rethans
JDI Media Solutions
H.v.Tussenbroekstraat 1
6952 BL Dieren
The Netherlands
e-mail: d.rethans@jdimedia.nl
http://www.jdimedia.nl/