mb_strcut
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
mb_strcut — 獲取字元的一部分
說明
mb_strcut(
string
int
int
string
): string
string
$str,int
$start,int
$length = NULL,string
$encoding = mb_internal_encoding()): string
mb_strcut() 和 mb_substr() 類似,都是從字串中提取子字串,但是按位元組數來執行,而不是字元個數。 如果截斷位置位於多位元組字元兩個位元組的中間,將於該字元的第一個位元組開始執行。 這也是和 substr() 函式的不同之處,後者簡單地將字串在位元組之間截斷,這將導致一個畸形的位元組序列。
參數
-
str -
要截斷的 string。
-
start -
如果
start不是負數,返回的字串會從str的第start位元組位置開始,從 0 開始計數。舉個例子,字串 'abcdef',位元組位置0的字元是 'a',位元組位置2的字元是 'c',以此類推。如果
start是負數,返回的字串是從str末尾處第start個位元組開始的。 -
length -
位元組長度。If omitted or
NULLis passed, extract all bytes to the end of the string. -
encoding -
encoding參數為字元編碼。如果省略或是null,則使用內部字元編碼。
返回值
mb_strcut() 根據 start 和 length 參數返回 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.
|