``split``
-========
+=========
-The ``split`` filter returns a list of items from a string that's separated by the provided delimiter:
+The ``split`` filter splits a string by the given delimiter and returns a list
+of strings:
.. code-block:: jinja
{{ "one,two,three"|split(',') }}
- {# returns [one, two, three] #}
+ {# returns ['one', 'two', 'three'] #}
-A limit parameter is available which the returned list will contain a maximum of limit elements with the last element containing the rest of string.
-If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string.
-If the limit parameter is negative, all components except the last -limit are returned.
-If the limit parameter is zero, then this is treated as 1.
+You can also pass a ``limit`` argument:
+
+ * If ``limit`` is positive, the returned array will contain a maximum of
+ limit elements with the last element containing the rest of string;
+
+ * If ``limit`` is negative, all components except the last -limit are
+ returned;
+
+ * If ``limit`` is zero, then this is treated as 1.
.. code-block:: jinja
{{ "one,two,three,four,five"|split(',', 3) }}
{# returns [one, two, "three,four,five"] #}
-If delimiter is an empty string, then value will be splitted by equal chunks. Length is set by limit parameter (1 char by default).
+If the ``delimiter`` is an empty string, then value will be split by equal
+chunks. Length is set by the ``limit`` argument (one character by default).
.. code-block:: jinja
.. note::
- Internally, Twig uses the PHP `explode`_ or `str_split`_ (if delimiter is empty) functions for string splitting.
-
-.. _`explode`: http://php.net/explode
+ Internally, Twig uses the PHP `explode`_ or `str_split`_ (if delimiter is
+ empty) functions for string splitting.
+.. _`explode`: http://php.net/explode
.. _`str_split`: http://php.net/str_split
/**
* Splits the string into an array.
*
- * The second parameter is option for the limit.
- * If delimiter is an empty string, then string is split by equal chunks. Chunk length is 1 char by default, or set
- * by limit
- *
* <pre>
* {{ "one,two,three"|split(',') }}
* {# returns [one, two, three] #}
* </pre>
*
* @param string $value A string
- * @param string $delimiter The separator to explode by
+ * @param string $delimiter The delimiter
* @param integer $limit The limit
*
- * @return string The explode'ed string
+ * @return array The split string as an array
*/
function twig_split_filter($value, $delimiter, $limit = null)
{