PHP - explode
Trieda
Metóda - explode
(PHP 4, PHP 5, PHP 7)
The function with an expressive name splits a string into a few substrings by a delimiter and returns them in an array. Simply, it converts the string to the array of substrings. It's a very useful function for parsing pretty URLs, simple CSV files, a date in a string format etc.
Procedurálne
- function explode (string $delimiter, string $string, int $limit = PHP_INT_MAX) : array
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $delimiter | string | The delimiter for splitting a string. | |
| $string | string | The input string. | |
| $limit | int | PHP_INT_MAX | A limit of array elements can be set as an optional parameter. If positive, the array will contain the given number of elements and the last element will contain the rest of the string that does not fit into the array. If negative, the array will contain all elements except the last few specified by the negative limit. The limit of 0 is treated as 1. |
Mávratovej hodnoty
Vracia: array
Returns an array of elements of a split string.
Príklady
<?php
$s = 'one,two,three,four,five,six,seven';
$array = explode(',', $s);
print_r($array);
Let's try to set the limit of the function:
<?php
$s = 'one,two,three,four,five,six,seven';
$array = explode(',', $s, 3);
print_r($array);
Súvisiace manuály
- function implode (string $glue, array $pieces) : string
