= 4.0.6, PHP 5, PHP 7, PHP 8)mb_strcut — 獲取字符的一部分說明mb_strcut( string $str, int $start, int $length = NULL, string $encodi">
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
mb_strcut — 獲取字符的一部分
$str,$start,$length = NULL,$encoding = mb_internal_encoding()mb_strcut() 和 mb_substr() 類似,都是從字符串中提取子字符串,但是按字節(jié)數(shù)來執(zhí)行,而不是字符個數(shù)。 如果截?cái)辔恢梦挥诙嘧止?jié)字符兩個字節(jié)的中間,將于該字符的第一個字節(jié)開始執(zhí)行。 這也是和 substr() 函數(shù)的不同之處,后者簡單地將字符串在字節(jié)之間截?cái)?,這將導(dǎo)致一個畸形的字節(jié)序列。
str要截?cái)嗟?string。
start
如果 start 不是負(fù)數(shù),返回的字符串會從 str 的第 start 字節(jié)位置開始,從 0 開始計(jì)數(shù)。舉個例子,字符串 'abcdef',字節(jié)位置 0 的字符是 'a',字節(jié)位置 2 的字符是
'c',以此類推。
如果 start 是負(fù)數(shù),返回的字符串是從 str 末尾處第 start 個字節(jié)開始的。
length
字節(jié)長度。If omitted or NULL
is passed, extract all bytes to the end of the string.
encodingencoding
參數(shù)為字符編碼。如果省略或是 null,則使用內(nèi)部字符編碼。
mb_strcut() 根據(jù) start 和 length 參數(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.
|