NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - explode

Trieda

Koreň \ Bez triedy

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ázovDátový typPredvolená hodnotaPopis
$delimiterstring

The delimiter for splitting a string.

$stringstring

The input string.

$limitint 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
      Aktivity