HH\Lib\Str\split

Meta Engineer?

This is available as Str\split in the www repository.

Returns a vec containing the string split on the given delimiter

namespace HH\Lib\Str;

function split(
  string $string,
  string $delimiter,
  ?int $limit = NULL,
): vec<string>;

The vec will not contain the delimiter itself.

If the limit is provided, the vec will only contain that many elements, where the last element is the remainder of the string.

To split the string into equally-sized chunks, see Str\chunk(). To use a pattern as delimiter, see Regex\split().

Previously known as explode in PHP.

Guide

Parameters

  • string $string
  • string $delimiter
  • ?int $limit = NULL

Returns

  • vec<string>

Examples

$str = "This, is, a, great, software, for sure.";
$split_str = Str\split($str, ",");
\print_r($split_str);

$split_str2 = Str\split($str, ",", 3);
\print_r($split_str2);