PHP mb_substr()Functions
Examples
Return "Rookie" from the string:
echo mb_substr("Example", 0, 2);
//Output: Rookie
Definition and Usage
The mb_substr() function returns a part of a string. Previously we learned the substr() function, which only works with English characters. If you want to split Chinese text, you need to use mb_substr().
Note:If the start parameter is negative and length is less than or equal to start, then length is 0.
Syntax
mb_substr ( string $str , int $start [, int $length = NULL [, string $encoding = mb_internal_encoding() ]] ) : string
| Parameter | Description |
|---|---|
| str | Required. Extracts a substring from this string. |
| start | Required. Specifies where in the string to start.
|
| length | Optional. Specifies the length of the string to return. The default is until the end of the string.
|
| encoding | Optional. Character encoding. If omitted, the internal character encoding is used. |
Technical Details
| Return value: | Returns the extracted part of the string, or FALSE on failure, or an empty string. |
|---|---|
| PHP Version: | 4+ |
PHP String Reference Manual Other Extensions