PHP
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.
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.
$str1 = "Today is Wednesday";
$newstr = substr($str1, 0, 5);
The substr function gets the substring starting at index 9 - W - and brings the 4 characters from this starting point.
$str1 = "Today is Wednesday";
$newstr = substr($str1, 9, 4);
The substr function gets the substring starting at index 9 - W - and brings the remaining of the characters until the end of the string.
$str1 = "Today is Wednesday";
$newstr = substr($str1, 9);
The substr function gets the substring starting at index -3 - d - This is the third character counting from the right.
$str1 = "Today is Wednesday";
$newstr = substr($str1, -3);
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.
$str1 = "Today is Wednesday";
$newstr = substr($str1, -6, 3);
Copyright © 2006-2012, LQ Systems,Inc. All rights reserved.