substr()

Deprecated in 5.0.

Replaced with method substring() of the string instance.

substr(string, n, len): void

Extracts the substring from string that begins at the nth character and is of length len.

Table 1. Parameters

string

String

Source string.

n

Integer

Starting character index for substring. The n must be a positive whole number. If n is greater than length(string), then empty string is returned.

len

Integer

Length of substring. If you omit length, the rest of the string is returned. Optional parameter.

Return

Extracted substring.

print(substr("abcdef", 3, 2)); //Will print: "cd"
print(substr("abcdef", 8)); //Will print: ""
print(substr("abcdef", 4)); //Will print: "def"