How to get first 5 characters from string in php The substr() function returns a part of a string in php. Note: If the start parameter is a negative number and length is less than or equal to start, length becomes 0.