Skip to content
Advertisement

how to force space to %20 in http_build_query?

I am facing a problem, that the API endpoint expects one of parameters with %20 replacing one of the spaces. Example:

$params = array(
           'client_id' => self::$client_id,
           'scope' => 'api%20offline_access', //here I need the %20 sign
           'response_type' => 'code',
           'redirect_uri' => self::$redirect_uri
          );

If I write 'scope' => 'api offline_access' the space gets translated to + sign when passing it to http_build_query() function.

If I keep it like it is above, the sign is “wrapped” with more signs

I tried to find this answer in the function manual, but with no luck

Advertisement

Answer

As @Paul replied :

http_build_query($params, null, null, PHP_QUERY_RFC3986);

According to php doc for enc_type parameter.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement