ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
You should put some validation on $i, maybe default it to zero and certainly check that it is not greater than the length of the string passed in use strlen(). You may want to use the result of strlen() in your for loop terminator.
Also, please sort out your indentation, it's quite confusing
As was stated in the original response by paulsm4 is your string null terminated? I don't think so. Maybe it was in earlier versions of PHP but it would be better to change your code to use the strlen() function.
One more thought, if $i is not passed in as 0, say 10, then your returned string will start at that location (thus characters will be chopped off from the original string). If that is what you want fine, if not then you may want to change the initialise statement in the for loop from $j = 0 to $j = $i