Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

mb_substr

Description

Get part of string

Syntax

mb_substr(
    string $string,
    int $start,
    ?int $length = null,
    ?string $encoding = null
): string

Parameters

string

The string to extract the substring from.

start

If start is non-negative, the returned string will start at the start'th position in string, counting from zero.

If start is negative, the returned string will start at the start'th character from the end of string.

length

Maximum number of characters to use from string. If omitted or null is passed, extract all characters to the end of the string.

encoding

The encoding parameter is the character encoding. If it is omitted or null, the internal character encoding value will be used.

Return

Returns the portion of string specified by the start and length parameters.

Examples

1 · string start · negative

<?

$string = '🐘string';
$start = -1;

$return = mb_substr($string, $start);

echo $return;

?>
g

2 · string start · non-negative

<?

$string = '🐘string';
$start = 1;

$return = mb_substr($string, $start);

echo $return;

?>
string

3 · length

<?

$string = '🐘string';
$start = 1;
$length = 3;

$return = mb_substr($string, $start, $length);

echo $return;

?>
str

4 · encoding

<?

$string = '🐘string';
$start = 1;
$length = 3;
$encoding = 'UTF-8';

$return = mb_substr($string, $start, $length, $encoding);

echo $return;

?>
str
HomeMenu