between

Returns the substring between $start and $end.

Description

static between(string $start, string $end, int $offset, bool $include)

An optional offset may be supplied from which to begin the search for the start string.

Parameters

  • string $start
    Delimiter marking the start of the substring.

  • string $end
    Delimiter marking the end of the substring.

  • int $offset
    Index from which to begin the search.

  • bool $include
    If true, we include the start & end in the result.

Return Value

static
Str object between $start & $end.

Examples

$expected = 'Hello';
$str = new Str('<p>Hello</p>');
assert($str->between('<p>', '</p>') == $expected);

An optional offset may be supplied from which to begin the search for the start string.

$expected = 'World';
$str = new Str('<p>Hello</p><p>World</p>');
assert($str->between('<p>', '</p>', 12) == $expected); // true

By default this method will discard the $start & $end substrings. If you wish to include them, set the $include parameter to true.

$expected = '<p>World</p>';
$str = new Str('<p>Hello</p><p>World</p>');
assert($str->between('<p>', '</p>', 12, true) == $expected); // true