Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP mb_substr() Function

PHP mb_substr() Function

PHP String Reference Manual PHP String Reference Manual

Example

Return "Runoob" from a string:


Definition and Usage

The mb_substr() function returns a part of a string. We learned the substr() function earlier, which only works on English characters; 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

Parameters Description
str Required. The string to extract the substring from.
start Required. Specifies where in the string to start.
  • Positive - Start at the specified position in the string
  • Negative - Start at the specified position from the end of the string
  • 0 - Start at the first character of the string
  • | | *length* | Optional. Specifies the length of the string to return. Default is to 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, FALSE on failure, or an empty string.
    PHP Version: 4+

    PHP String Reference Manual PHP String Reference Manual