PUBLIE : |explode

**SPIP**

# Article validé

L’article "**|explode** (https://www.spip.net/en_article6568.html)" vient
d’être publié par b_b.

* * *

## |explode

mardi 26 mai 2020 , par [jack](.././?page=auteur&id_auteur=593&)

The filter **`|explode`** allows to cut a string according to a specified
separator and to place each element in an array (array in the PHP sense).

For example, from `#SET{ma_date, '31/12/1999'}`,
`#SET{my_array, #GET{my_date}|explode{/}}` will generate the array having
for elements "31", "12" and "1999" ; `[(#GET{my_array}|foreach)]` will thus
return :

    0 => 31
    1 => 12
    2 => 1999

**Warning :**
- if the separator is the comma character, you have to enclose it in single
quotes : `#SET{my_array, #GET{my_variable}|explode{','}}`
- To make the filter more convenient to use in templates, `|explode`
reverses the writing of the PHP function of the same name.

* * *

See also the filter |implode
(https://www.spip.net/ecrire/?exec=article&id_article=6569)

— Envoyé par SPIP (https://www.spip.net/)

rubon199.jpg

puce.gif