You can use the built-in PHP substr($string, $offset, $length) function to get a part of a string. The $offset indicates the position at which the substr() function starts to extract the substring. In PHP, indexing starts at 0. A negative value means that substr() will return a substring beginning at an $offset from the end of the string. If the optional $length parameter is passed, substr() will return the specified number of characters. If $length is negative, then the specified number of characters will be omitted at the end of the string. In this PHP substr() example, we extract the first three characters from a string. Click Execute to run the PHP substr() function online and see the result.