LQ Systems

PHP Substr Functions

by Linda Quinn






LQ Net Blog
















   Printer Friendly Page


SUBSTR - Substring


substr(str, start, length)

Extracts characters from a string, given the starting position and the length to be retrieved.

str is the string being processed.


start is the index of the starting character.

The index for the first character is 0.

If the index is a negative number, the returned substring will start at the index number from the right. (see example below)


length is the number of characters to return.

If this is blank, the characters from the start index to the end of the string is returned.



Start index at 0, get 5 characters


The substr function has been told to get the substring starting at index 0, which is the first character - T - and to get the first 5 characters from the start point.






Start index at 9, get 4 characters


The substr function gets the substring starting at index 9 - W - and brings the 4 characters from this starting point.






Start index at 9


The substr function gets the substring starting at index 9 - W - and brings the remaining of the characters until the end of the string.



Start index at -3


The substr function gets the substring starting at index -3 - d - This is the third character counting from the right.






Start index at -6, get 3 characters


The substr function gets the substring starting at index -6 - n - This is the sixth character counting from the right. The length parameter says to retrieve 3 characters.





Please read our blog on MS Office VBA


LQExcel Blog






Copyright © 2006-2012, LQ Systems,Inc. All rights reserved.