url_encode
¶
这个 url_encode
筛选器百分比将给定字符串编码为URL段或数组作为查询字符串:
1 2 3 4 5 6 7 8 | {{ "path-seg*ment"|url_encode }}
{# outputs "path-seg%2Ament" #}
{{ "string with spaces"|url_encode }}
{# outputs "string%20with%20spaces" #}
{{ {'param': 'value', 'foo': 'bar'}|url_encode }}
{# outputs "param=value&foo=bar" #}
|
注解
在内部,Twig使用PHP rawurlencode 或 http_build_query 功能。