Menu Riverview Church

SUBSTR

Return part of a string

SYNTAX

substr ( string $string , int $start [, int $length ] ) : string

PARAMETERS

string

The input string.

start

If start is non-negative, the returned string will start at the start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth. If start is negative, the returned string will start at the start'th character from the end of string. If string is less than start characters long, FALSE will be returned.

length

If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string). If length is given and is negative, then that many characters will be omitted from the end of string (after the start position has been calculated when a start is negative). If start denotes the position of this truncation or beyond, FALSE will be returned. If length is given and is 0, FALSE or NULL, an empty string will be returned. If length is omitted, the substring starting from start until the end of the string will be returned.

RETURN

Returns the extracted part of string; or FALSE on failure, or an empty string.

EXAMPLES

STRING START | NEGATIVE

start:-5 return:abcde
start:-4 return:bcde
start:-3 return:cde
start:-2 return:de
start:-1 return:e

STRING START | NON-NEGATIVE

start:0 return:abcde
start:1 return:bcde
start:2 return:cde
start:3 return:de
start:4 return:e

LENGTH | NEGATIVE

start:-5 length:-5 return:
start:-5 length:-4 return:a
start:-5 length:-3 return:ab
start:-5 length:-2 return:abc
start:-5 length:-1 return:abcd
start:-4 length:-5 return:
start:-4 length:-4 return:
start:-4 length:-3 return:b
start:-4 length:-2 return:bc
start:-4 length:-1 return:bcd
start:-3 length:-5 return:
start:-3 length:-4 return:
start:-3 length:-3 return:
start:-3 length:-2 return:c
start:-3 length:-1 return:cd
start:-2 length:-5 return:
start:-2 length:-4 return:
start:-2 length:-3 return:
start:-2 length:-2 return:
start:-2 length:-1 return:d
start:-1 length:-5 return:
start:-1 length:-4 return:
start:-1 length:-3 return:
start:-1 length:-2 return:
start:-1 length:-1 return:
start:0 length:-5 return:
start:0 length:-4 return:a
start:0 length:-3 return:ab
start:0 length:-2 return:abc
start:0 length:-1 return:abcd
start:1 length:-5 return:
start:1 length:-4 return:
start:1 length:-3 return:b
start:1 length:-2 return:bc
start:1 length:-1 return:bcd
start:2 length:-5 return:
start:2 length:-4 return:
start:2 length:-3 return:
start:2 length:-2 return:c
start:2 length:-1 return:cd
start:3 length:-5 return:
start:3 length:-4 return:
start:3 length:-3 return:
start:3 length:-2 return:
start:3 length:-1 return:d
start:4 length:-5 return:
start:4 length:-4 return:
start:4 length:-3 return:
start:4 length:-2 return:
start:4 length:-1 return:

LENGTH | NON-NEGATIVE

start:-5 length:0 return:
start:-5 length:1 return:a
start:-5 length:2 return:ab
start:-5 length:3 return:abc
start:-5 length:4 return:abcd
start:-4 length:0 return:
start:-4 length:1 return:b
start:-4 length:2 return:bc
start:-4 length:3 return:bcd
start:-4 length:4 return:bcde
start:-3 length:0 return:
start:-3 length:1 return:c
start:-3 length:2 return:cd
start:-3 length:3 return:cde
start:-3 length:4 return:cde
start:-2 length:0 return:
start:-2 length:1 return:d
start:-2 length:2 return:de
start:-2 length:3 return:de
start:-2 length:4 return:de
start:-1 length:0 return:
start:-1 length:1 return:e
start:-1 length:2 return:e
start:-1 length:3 return:e
start:-1 length:4 return:e
start:0 length:0 return:
start:0 length:1 return:a
start:0 length:2 return:ab
start:0 length:3 return:abc
start:0 length:4 return:abcd
start:1 length:0 return:
start:1 length:1 return:b
start:1 length:2 return:bc
start:1 length:3 return:bcd
start:1 length:4 return:bcde
start:2 length:0 return:
start:2 length:1 return:c
start:2 length:2 return:cd
start:2 length:3 return:cde
start:2 length:4 return:cde
start:3 length:0 return:
start:3 length:1 return:d
start:3 length:2 return:de
start:3 length:3 return:de
start:3 length:4 return:de
start:4 length:0 return:
start:4 length:1 return:e
start:4 length:2 return:e
start:4 length:3 return:e
start:4 length:4 return:e

PHP