Yaffs site version 1.1
[yaffs-website] / vendor / twig / twig / doc / filters / url_encode.rst
1 ``url_encode``
2 ==============
3
4 .. versionadded:: 1.12.3
5     Support for encoding an array as query string was added in Twig 1.12.3.
6
7 .. versionadded:: 1.16.0
8     The ``raw`` argument was removed in Twig 1.16.0. Twig now always encodes
9     according to RFC 3986.
10
11 The ``url_encode`` filter percent encodes a given string as URL segment
12 or an array as query string:
13
14 .. code-block:: jinja
15
16     {{ "path-seg*ment"|url_encode }}
17     {# outputs "path-seg%2Ament" #}
18
19     {{ "string with spaces"|url_encode }}
20     {# outputs "string%20with%20spaces" #}
21
22     {{ {'param': 'value', 'foo': 'bar'}|url_encode }}
23     {# outputs "param=value&foo=bar" #}
24
25 .. note::
26
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.)
31
32 .. _`urlencode`:        http://php.net/urlencode
33 .. _`rawurlencode`:     http://php.net/rawurlencode
34 .. _`http_build_query`: http://php.net/http_build_query