English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP mb_substr() Function Usage and Example

PHP String Reference Manual

Online Example

Returns "Basic Tutorial" from the string:

<?php
echo mb_substr("Basic Tutorial Website", 0, 4);
// Output: Tutorial Tutorial
?>
Test and see ‹/›

Definition and Usage

The mb_substr() function returns a part of the string. We have learned about the substr() function before, which is only for English characters. If you need to split Chinese characters, you need to use mb_substr().

Note:If the start parameter is negative and the 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
ParametersDescription
strRequired. Extract a substring from this string.
startRequired. Specify where to start in the string.
  • Positive number - Starts at the specified position in the string

  • Negative number - Starts from the specified position from the end of the string

  • 0 - Starts at the first character in the string

lengthOptional. Specify the length of the string to return. The default is to the end of the string.
  • Positive number - Returns from the position of the start parameter

  • Negative number - Returns from the end of the string

encodingOptional. Character encoding. If omitted, the internal character encoding is used.

Technical Details

Return value:Returns the extracted part of the string, or FALSE if the operation fails, or an empty string.
PHP Version:4+


PHP String Reference Manual