PHP mb_ Substr mbstring function


Definition and Usage

mb_substr– get partial string

Version support

support support support

5.4.8 null is passed in the length, which is extracted from the start to the end of the string. In previous versions, null was treated as 0.


mb_substr( string $str , int $start [, int $length = NULL [, string $encoding = mb_internal_encoding() ]] )

  mb_substr()Performs a multibyte safe substr() operation based on the number of characters. The position is counted from the start of the str. The position of the first character is 0. The position of the second character is 1, and so on.


parameter Required describe
str yes Extract the substring from the string.
start yes If start is not a negative number, the string returned will start at STR start and count from 0. For example, the string ‘ABCDEF’, the character at position 0 is’ a ‘, the character at position 2 is’ C’, and so on. If start is a negative number, the string returned starts with the start character at the end of str.
length yes The maximum number of characters to use in str. If this parameter is omitted or null is passed in, the end of the string is extracted.
encoding no

The encoding parameter is character encoding. If omitted, internal character encoding is used.

Return value

Function returns the specified part of STR according to the start and length parameters.


echo mb_substr("hello world",2,3); 


Related pages

Mb_ Strcut() – get part of the character
Mb_ internal_ Encoding() – set / get internal character encoding