Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

substr

and 3-argument forms)

Extracts a substring from a string.

Returns the portion of STRING starting at character position OFFSET. If OFFSET is negative, it counts backwards from the end of the string. When LENGTH is given, at most that many characters are extracted; a negative LENGTH leaves that many characters at the end.

The argument count is encoded in the lower 4 bits of the op’s private flags (set by codegen). When those bits are zero (e.g. bytecode/JSON fallback path), the stack length is used instead.

Synopsis

$part = substr($string, $offset);
$part = substr($string, $offset, $length);

See Also

index, rindex, substr