4 .. versionadded:: 1.12.3
5 Support for encoding an array as query string was added in Twig 1.12.3.
7 .. versionadded:: 1.16.0
8 The ``raw`` argument was removed in Twig 1.16.0. Twig now always encodes
11 The ``url_encode`` filter percent encodes a given string as URL segment
12 or an array as query string:
16 {{ "path-seg*ment"|url_encode }}
17 {# outputs "path-seg%2Ament" #}
19 {{ "string with spaces"|url_encode }}
20 {# outputs "string%20with%20spaces" #}
22 {{ {'param': 'value', 'foo': 'bar'}|url_encode }}
23 {# outputs "param=value&foo=bar" #}
27 Internally, Twig uses the PHP `urlencode`_ (or `rawurlencode`_ if you pass
28 ``true`` as the first parameter) or the `http_build_query`_ function. Note
29 that as of Twig 1.16.0, ``urlencode`` **always** uses ``rawurlencode`` (the
30 ``raw`` argument was removed.)
32 .. _`urlencode`: http://php.net/urlencode
33 .. _`rawurlencode`: http://php.net/rawurlencode
34 .. _`http_build_query`: http://php.net/http_build_query