The mb_substr()
function in PHP is used to extract a substring from a given string. It is similar to the substr()
function, but it supports multi-byte encoding.
The basic syntax of mb_substr()
is as follows:
mb_substr(string $str, int $start [, int $length [, string $encoding = mb_internal_encoding() ]]): string|false
$str
is the input string from which the substring will be extracted.$start
is the starting position of the substring. If it is positive, the counting starts from the beginning of the string. If it is negative, the counting starts from the end of the string.$length
(optional) specifies the length of the substring to be extracted. If not provided, it will extract all characters from the starting position to the end of the string.$encoding
(optional) specifies the character encoding. If not provided, it uses the internal encoding set by mb_internal_encoding()
.The function returns the extracted substring as a string, or false
if an error occurs.
Example usage:
$str = "Hello, World!";
$substr = mb_substr($str, 7, 5); // Extracts "World"
echo $substr;
In this example, the mb_substr()
function is used to extract the substring "World" starting from position 7 in the string "Hello, World!".
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站