It is easier than that. Your end index must never be greater than the end index of your string, so that is the value to check in your loop. Something like :
def all_possible_substring(string, start, end){
WHILE (end < string.length - 1)
println( string[start:end])
start += 1
end += 1
}
}
all_possible_substring( "abcdef" , 0, 2) // test it off
Yes, I know this is not PHP, but the logic is the same.