HH\Lib\Str\slice

This API is part of the Hack Standard Library, not HHVM itself.
Facebook Engineer?

This function is available as Str\slice() in Facebook's www repository.

Returns a substring of length $length of the given string starting at the $offset

Description

namespace HH\Lib\Str;

function slice(
  string $string,
  int $offset,
  ?int $length = null,
): string;

If no length is given, the slice will contain the rest of the string. If the length is zero, the empty string will be returned. If the offset is out-of-bounds, a ViolationException will be thrown.

Previously known as substr in PHP.

Parameters

  • string $string
  • int $offset
  • ?int $length = null