Added optional parameter to http_build_query() to allow specification of

string separator.
This commit is contained in:
Ilia Alshanetsky 2005-08-31 01:19:40 +00:00
parent 4f1520912c
commit 50fb7a8261
3 changed files with 17 additions and 12 deletions

2
NEWS
View file

@ -4,6 +4,8 @@ PHP NEWS
- Unicode support. (Andrei, Dmitriy, et al) - Unicode support. (Andrei, Dmitriy, et al)
- Changed "instanceof" operator, is_a() and is_subclass_of() functions to not - Changed "instanceof" operator, is_a() and is_subclass_of() functions to not
call __autoload(). (Dmitry) call __autoload(). (Dmitry)
- Added optional parameter to http_build_query() to allow specification of
string separator.
- cURL improvements: (Ilia) - cURL improvements: (Ilia)
. Added curl_setopt_array() which allows setting of multiple cURL options. . Added curl_setopt_array() which allows setting of multiple cURL options.
. Added CURLINFO_HEADER_OUT to facilitate request retrieval. . Added CURLINFO_HEADER_OUT to facilitate request retrieval.

View file

@ -29,9 +29,9 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
const char *num_prefix, int num_prefix_len, const char *num_prefix, int num_prefix_len,
const char *key_prefix, int key_prefix_len, const char *key_prefix, int key_prefix_len,
const char *key_suffix, int key_suffix_len, const char *key_suffix, int key_suffix_len,
zval *type TSRMLS_DC) zval *type, char *arg_sep TSRMLS_DC)
{ {
char *arg_sep = NULL, *key = NULL, *ekey, *newprefix, *p; char *key = NULL, *ekey, *newprefix, *p;
int arg_sep_len, key_len, ekey_len, key_type, newprefix_len; int arg_sep_len, key_len, ekey_len, key_type, newprefix_len;
ulong idx; ulong idx;
zval **zdata = NULL, *copyzval; zval **zdata = NULL, *copyzval;
@ -45,9 +45,11 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
return SUCCESS; return SUCCESS;
} }
arg_sep = INI_STR("arg_separator.output"); if (!arg_sep) {
if (!arg_sep || !strlen(arg_sep)) { arg_sep = INI_STR("arg_separator.output");
arg_sep = URL_DEFAULT_ARG_SEP; if (!arg_sep || !strlen(arg_sep)) {
arg_sep = URL_DEFAULT_ARG_SEP;
}
} }
arg_sep_len = strlen(arg_sep); arg_sep_len = strlen(arg_sep);
@ -127,7 +129,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
*p = '\0'; *p = '\0';
} }
ht->nApplyCount++; ht->nApplyCount++;
php_url_encode_hash_ex(HASH_OF(*zdata), formstr, NULL, 0, newprefix, newprefix_len, "]", 1, (Z_TYPE_PP(zdata) == IS_OBJECT ? *zdata : NULL) TSRMLS_CC); php_url_encode_hash_ex(HASH_OF(*zdata), formstr, NULL, 0, newprefix, newprefix_len, "]", 1, (Z_TYPE_PP(zdata) == IS_OBJECT ? *zdata : NULL), arg_sep TSRMLS_CC);
ht->nApplyCount--; ht->nApplyCount--;
efree(newprefix); efree(newprefix);
} else if (Z_TYPE_PP(zdata) == IS_NULL || Z_TYPE_PP(zdata) == IS_RESOURCE) { } else if (Z_TYPE_PP(zdata) == IS_NULL || Z_TYPE_PP(zdata) == IS_RESOURCE) {
@ -183,16 +185,17 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
} }
/* }}} */ /* }}} */
/* {{{ proto string http_build_query(mixed formdata [, string prefix]) /* {{{ proto string http_build_query(mixed formdata [, string prefix [, string arg_separator]])
Generates a form-encoded query string from an associative array or object. */ Generates a form-encoded query string from an associative array or object. */
PHP_FUNCTION(http_build_query) PHP_FUNCTION(http_build_query)
{ {
zval *formdata; zval *formdata;
char *prefix = NULL; char *prefix = NULL, *arg_sep=NULL;
int prefix_len = 0; int arg_sep_len, prefix_len = 0;
smart_str formstr = {0}; smart_str formstr = {0};
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s", &formdata, &prefix, &prefix_len) != SUCCESS) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ss", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len) != SUCCESS) {
RETURN_FALSE; RETURN_FALSE;
} }
@ -201,7 +204,7 @@ PHP_FUNCTION(http_build_query)
RETURN_FALSE; RETURN_FALSE;
} }
if (php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL) TSRMLS_CC) == FAILURE) { if (php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep TSRMLS_CC) == FAILURE) {
if (formstr.c) { if (formstr.c) {
efree(formstr.c); efree(formstr.c);
} }

View file

@ -28,7 +28,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
const char *num_prefix, int num_prefix_len, const char *num_prefix, int num_prefix_len,
const char *key_prefix, int key_prefix_len, const char *key_prefix, int key_prefix_len,
const char *key_suffix, int key_suffix_len, const char *key_suffix, int key_suffix_len,
zval *type TSRMLS_DC); zval *type, char *arg_sep TSRMLS_DC);
#define php_url_encode_hash(ht, formstr) php_url_encode_hash_ex((ht), (formstr), NULL, 0, NULL, 0, NULL, 0, NULL TSRMLS_CC) #define php_url_encode_hash(ht, formstr) php_url_encode_hash_ex((ht), (formstr), NULL, 0, NULL, 0, NULL, 0, NULL TSRMLS_CC)
PHP_FUNCTION(http_build_query); PHP_FUNCTION(http_build_query);