= 4.0.6, PHP 5, PHP 7, PHP 8)mb_strcut — 獲取字符的一部分說明mb_strcut( string $str, int $start, int $length = NULL, string $encodi">

mb_strcut

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

mb_strcut獲取字符的一部分

說明

mb_strcut(
    string $str,
    int $start,
    int $length = NULL,
    string $encoding = mb_internal_encoding()
): string

mb_strcut()mb_substr() 類似,都是從字符串中提取子字符串,但是按字節(jié)數(shù)來執(zhí)行,而不是字符個數(shù)。 如果截斷位置位于多字節(jié)字符兩個字節(jié)的中間,將于該字符的第一個字節(jié)開始執(zhí)行。 這也是和 substr() 函數(shù)的不同之處,后者簡單地將字符串在字節(jié)之間截斷,這將導致一個畸形的字節(jié)序列。

參數(shù)

str

要截斷的 string

start

如果 start 不是負數(shù),返回的字符串會從 str 的第 start 字節(jié)位置開始,從 0 開始計數(shù)。舉個例子,字符串 'abcdef',字節(jié)位置 0 的字符是 'a',字節(jié)位置 2 的字符是 'c',以此類推。

如果 start 是負數(shù),返回的字符串是從 str 末尾處第 start 個字節(jié)開始的。

length

字節(jié)長度。If omitted or NULL is passed, extract all bytes to the end of the string.

encoding

encoding 參數(shù)為字符編碼。如果省略或是 null,則使用內(nèi)部字符編碼。

返回值

mb_strcut() 根據(jù) startlength 參數(shù)返回 str 的一部分。

更新日志

版本 說明
5.4.8 Passing NULL as length extracts all bytes to the end of the string. Prior to this version NULL was treated the same as 0.

參見