Hello,
I made a patch to add the RFC-3984 based url-encoding support
into http_build_query()
.
The http_build_query()
is quite useful, but,
it isn't based on the official url-encoding scheme (RFC-3984)
for ~ (tilde) and ' '(space).
I added an optional (the 4th) parameter 'is_rfc3984'.
If it is true (false by default, now), RFC3984 based
url-encoding scheme (it is same as rawurlencode()
) is used.
A simple example shown as bellow,
$v = array('foo'=>'m o','boo'=>'[^~]');
// result: foo=m+p&boo=%5B%5E%7E5D
echo http_build_query($v, null, '&');
// result: foo=m%20p&boo=%5B%5E~5D (RFC-3986 compatible)
echo http_build_query($v, null, '&', true);
// result: foo=m%20p&boo=%5B%5E~5D (RFC-3986 compatible)
echo rawurlencode($v['foo']).'&'.rawurlencode($v['boo']);
I'm going to commit the patch if it is accepted.
Rui
Instead of a boolean, could you add a rfc-xx selection parameter instead,
like, in case one would like rfc 3986 instead?
Hello,
I made a patch to add the RFC-3984 based url-encoding support
intohttp_build_query()
.The
http_build_query()
is quite useful, but,
it isn't based on the official url-encoding scheme (RFC-3984)
for ~ (tilde) and ' '(space).I added an optional (the 4th) parameter 'is_rfc3984'.
If it is true (false by default, now), RFC3984 based
url-encoding scheme (it is same asrawurlencode()
) is used.A simple example shown as bellow,
$v = array('foo'=>'m o','boo'=>'[^~]');
// result: foo=m+p&boo=%5B%5E%7E5D
echo http_build_query($v, null, '&');// result: foo=m%20p&boo=%5B%5E~5D (RFC-3986 compatible)
echo http_build_query($v, null, '&', true);// result: foo=m%20p&boo=%5B%5E~5D (RFC-3986 compatible)
echo rawurlencode($v['foo']).'&'.rawurlencode($v['boo']);I'm going to commit the patch if it is accepted.
Rui
Hello,
Thank you for the comment.
How about adding two PHP constant,
PHP_QUERY_RFC1738 (default) and PHP_QUERY_RFC3986 ?
It is like,
echo http_build_query($v, null, '&');
echo http_build_query($v, null, '&',PHP_QUERY_RFC1738);
echo http_build_query($v, null, '&', PHP_QUERY_RFC3986);
Rui
(2011/01/05 21:17), Tjerk Meesters wrote:
Instead of a boolean, could you add a rfc-xx selection parameter
instead, like, in case one would like rfc 3986 instead?On Jan 5, 2011 8:10 PM, "Rui Hirokawa" <rui_hirokawa@yahoo.co.jp
mailto:rui_hirokawa@yahoo.co.jp> wrote:Hello,
I made a patch to add the RFC-3984 based url-encoding support
intohttp_build_query()
.The
http_build_query()
is quite useful, but,
it isn't based on the official url-encoding scheme (RFC-3984)
for ~ (tilde) and ' '(space).I added an optional (the 4th) parameter 'is_rfc3984'.
If it is true (false by default, now), RFC3984 based
url-encoding scheme (it is same asrawurlencode()
) is used.A simple example shown as bellow,
$v = array('foo'=>'m o','boo'=>'[^~]');
// result: foo=m+p&boo=%5B%5E%7E5D
echo http_build_query($v, null, '&');// result: foo=m%20p&boo=%5B%5E~5D (RFC-3986 compatible)
echo http_build_query($v, null, '&', true);// result: foo=m%20p&boo=%5B%5E~5D (RFC-3986 compatible)
echo rawurlencode($v['foo']).'&'.rawurlencode($v['boo']);I'm going to commit the patch if it is accepted.
Rui
Hello,
This is a revised patch based on the PHP constant.
Rui
(2011/01/05 21:50), Rui Hirokawa wrote:
Hello,
Thank you for the comment.How about adding two PHP constant,
PHP_QUERY_RFC1738 (default) and PHP_QUERY_RFC3986 ?It is like,
echo http_build_query($v, null, '&');
echo http_build_query($v, null, '&',PHP_QUERY_RFC1738);
echo http_build_query($v, null, '&', PHP_QUERY_RFC3986);Rui
(2011/01/05 21:17), Tjerk Meesters wrote:
Instead of a boolean, could you add a rfc-xx selection parameter
instead, like, in case one would like rfc 3986 instead?On Jan 5, 2011 8:10 PM, "Rui Hirokawa" <rui_hirokawa@yahoo.co.jp
mailto:rui_hirokawa@yahoo.co.jp> wrote:Hello,
I made a patch to add the RFC-3984 based url-encoding support
intohttp_build_query()
.The
http_build_query()
is quite useful, but,
it isn't based on the official url-encoding scheme (RFC-3984)
for ~ (tilde) and ' '(space).I added an optional (the 4th) parameter 'is_rfc3984'.
If it is true (false by default, now), RFC3984 based
url-encoding scheme (it is same asrawurlencode()
) is used.A simple example shown as bellow,
$v = array('foo'=>'m o','boo'=>'[^~]');
// result: foo=m+p&boo=%5B%5E%7E5D
echo http_build_query($v, null, '&');// result: foo=m%20p&boo=%5B%5E~5D (RFC-3986 compatible)
echo http_build_query($v, null, '&', true);// result: foo=m%20p&boo=%5B%5E~5D (RFC-3986 compatible)
echo rawurlencode($v['foo']).'&'.rawurlencode($v['boo']);I'm going to commit the patch if it is accepted.
Rui