定義和用法
mb_substr - 獲取部分字串版本支持
| PHP4 | PHP5 | PHP7 |
|---|---|---|
| 支持 | 支持 | 支持 |
5.4.8 length 傳入 NULL,則從 start 提取到字串的結尾處, 在之前的版本里, NULL 會被當作 0 來處理,
語法
mb_substr( string $str , int $start [, int $length = NULL [, string $encoding = mb_internal_encoding() ]] )
mb_substr() 根據字符數執行一個多位元組安全的 substr() 操作, 位置是從 str 的開始位置進行計數, 第一個字符的位置是 0,第二個字符的位置是 1,以此類推,
引數
| 引數 | 必需的 | 描述 |
|---|---|---|
| str | 是 | 從該字串中提取子字串, |
| start | 是 | 如果 start 不是負數,回傳的字串會從 str 第 start 的位置開始,從 0 開始計數,舉個例子,字串 'abcdef',位置 0 的字符是 'a',位置 2 的字符是 'c',以此類推,如果 start 是負數,回傳的字串是從 str 末尾處第 start 個字符開始的, |
| length | 是 | str 中要使用的最大字符數,如果省略了此引數或者傳入了 NULL,則會提取到字串的尾部, |
| encoding | 否 |
encoding 引數為字符編碼,如果省略,則使用內部字符編碼, |
回傳值
函式根據 start 和 length 引數回傳 str 中指定的部分,示例
echo mb_substr("hello world",2,3);
相關頁面
mb_strcut() - 獲取字符的一部分 mb_internal_encoding() - 設定/獲取內部字符編碼轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/88067.html
標籤:PHP
上一篇:php的排序演算法
