sgapiSubStr(%%string,%%start = 0,%%length = 255)

This is equivalent to the substr function in PHP. This function returns the portion of string specified by the offset and length parameters.

If start is non-negative, the returned string will start at the start 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 character from the end of string.

If string is less than or equal to start characters long, FALSE will be returned.

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.

Examples

The below exampe will return "a"

%%string = 'abcdef';

%%output .= sgapiSubStr(%%string,0,1)

The below example will return "f"

%%string = 'abcdef';

%%output .= sgapiSubStr(%%string, %%start = -1);

The below example will return "ef"

%%string = 'abcdef';

%%output .= sgapiSubStr(%%string, %%start = -2);

The below example will return "d"

%%string = 'abcdef';

%%output .= sgapiSubStr(%%string, %%start = -3, %%length = 1);

The below example will return "cde"

%%string = 'abcdef';

%%output .= sgapiSubStr(%%string, %%start = 2, %%length = -1);

To see an example or learn more other PHP functions and PHP programming, visit PHP Documentation.