urlencode for PHP and Javascript

urlencode() & rawurlencode()

PHP urlencode() use RFC 2396 and rawurlencode() use RFC 3986, the later should be the correct solution. BTW, the result of rawurlencode() and encodeURI() of javascript will be the same.

http_build_query

http_build_query use urlencode() by default, but could be changed by adding some more params:

Reference: