The php Function Grapheme_Substr
PHP has many inbuilt functions that work with various types of data. One of the most important functions is substr, which is used to extract a specific part from a string. It is an essential tool for any developer, as it can be used to extract characters from the start of a string or even its end.
The php function grapheme_substr uses three parameters, two of which are mandatory and one is optional. The first parameter is the string from which a part needs to be extracted. The second parameter is the starting position in the string, which is an integer. The third parameter is the length of the string to be returned, which can be an integer or a number of characters.
if a value for the starting position is not passed, the string will be trimmed to the end of the string. If a positive number is passed, then the returning string will begin with the specified position in the string, which is counted from zero. If a negative number is passed, the string will be trimmed to start from the end of the string.
In PHP 8, the return type of the function has been changed to string|False to bring it in line with mb_substr and iconv_substr. In addition, both functions now clamp negative string offsets to the length of the input string. This brings them in line with their functionality before PHP 8.0, where they returned an empty string on negative offsets.