mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-07 09:41:01 +02:00
* Implemented support for substr, implode and json_encode as modifiers. Fixes #939 * Added split and join in favor of explode and implode modifiers. * Documented all available modifiers
1.0 KiB
1.0 KiB
split
Splits a string into an array, using the optional second parameter as the separator.
Basic usage
For $chars
populated with 'abc'
, the following will produce a html list with 3 elements (a, b and c).
<ol>
{foreach $chars|split as $char}
<li>{$char|escape}</li>
{/foreach}
</ol>
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
1 | string | No | separator used to split the string on. Defaults to empty string, causing each character in the source string to be separate. |
Examples
For $ids
populated with '1,2,3'
, the following will produce a html list with 3 elements (1, 2 and 3).
<ol>
{foreach $ids|split:',' as $id}
<li>{$id|escape}</li>
{/foreach}
</ol>