blob: 60cf365f1c8a597977aba32fe0c430805939ef62 [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001``url_encode``
2==============
3
4The ``url_encode`` filter percent encodes a given string as URL segment
5or an array as query string:
6
7.. code-block:: twig
8
9 {{ "path-seg*ment"|url_encode }}
10 {# outputs "path-seg%2Ament" #}
11
12 {{ "string with spaces"|url_encode }}
13 {# outputs "string%20with%20spaces" #}
14
15 {{ {'param': 'value', 'foo': 'bar'}|url_encode }}
16 {# outputs "param=value&foo=bar" #}
17
18.. note::
19
20 Internally, Twig uses the PHP `rawurlencode`_ or the `http_build_query`_ function.
21
22.. _`rawurlencode`: https://secure.php.net/rawurlencode
23.. _`http_build_query`: https://secure.php.net/http_build_query