💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# `split` New in version 1.10.3: The `split` filter was added in Twig 1.10.3. The `split` filter splits a string by the given delimiter and returns a listof strings: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2</pre></div></td><td class="code"><div class="highlight"><pre>{% set foo = "one,two,three"|split(',') %} {# foo contains ['one', 'two', 'three'] #} </pre></div></td></tr></table> You can also pass a `limit` argument: > > - If `limit` is positive, the returned array will contain a maximum oflimit elements with the last element containing the rest of string; > - If `limit` is negative, all components except the last -limit arereturned; > - If `limit` is zero, then this is treated as 1. <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2</pre></div></td><td class="code"><div class="highlight"><pre>{% set foo = "one,two,three,four,five"|split(',', 3) %} {# foo contains ['one', 'two', 'three,four,five'] #} </pre></div></td></tr></table> If the `delimiter` is an empty string, then value will be split by equalchunks. Length is set by the `limit` argument (one character by default). <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2 3 4 5</pre></div></td><td class="code"><div class="highlight"><pre>{% set foo = "123"|split('') %} {# foo contains ['1', '2', '3'] #} {% set bar = "aabbcc"|split('', 2) %} {# bar contains ['aa', 'bb', 'cc'] #} </pre></div></td></tr></table> Note Internally, Twig uses the PHP [explode](http://php.net/explode) [http://php.net/explode] or [str_split](http://php.net/str_split) [http://php.net/str_split] (if delimiter isempty) functions for string splitting. ### Arguments - `delimiter`: The delimiter - `limit`: The limit argument