# [PATCH] adding RFC3984 support to http_build_query

- Thread: https://externals.io/message/51217
- Original archive: https://news-web.php.net/php.internals/51217
- Started by Rui Hirokawa on 2011-01-05T12:08:59+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #51217 — Rui Hirokawa — 2011-01-05T12:08:59+00:00

URL: https://externals.io/message/51217#51217

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

---

## #51218 — Tjerk Meesters — 2011-01-05T12:17:39+00:00

URL: https://externals.io/message/51217#51218 · In reply to: #51217

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
> 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

---

## #51219 — Rui Hirokawa — 2011-01-05T12:50:09+00:00

URL: https://externals.io/message/51217#51219 · In reply to: #51218

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:
> > […]

---

## #51222 — Rui Hirokawa — 2011-01-05T15:09:25+00:00

URL: https://externals.io/message/51217#51222 · In reply to: #51219

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:
> > […]
