Both the function extract the part of the string from the given string. So I will concentrate on difference rather than full detailed explanation of these functions.
Both the functions have same number of parameters (two), but the parameter which makes them behave different than each other is the second parameter. Have a look at more details on this.
First Parameter indicates the starting point and second parameter indicates length of the string you want to generate.
So if you want to get the substring which start from second character and have a length of 5 character the below code with be used.
Like substr first parameter in substring indicates the starting index but second parameter indicates the ending index of the string.
So if you want to get the string from main string which start from second character and end at fifth char, below code will be used.
Now lets apply same parameter on both functions and check the output from the same string.
Hope you are clear with difference in these two functions. So you would have better idea for which one to use.
Share your thoughts on this via comments.
Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.
View all posts by: Avinash