chunk_split
將字符串拆分為較小的塊
chunk_split()
函數把字符串分割為一連串更小的部分。
註釋:該函數不改變原始字符串。
在每個字符後分割一次字符串,並在每個分割後添加".":
<?php $str = "Shanghai" ; echo chunk_split ( $str , 1 , "." ) ; ?>
親自試一試
在每六個字符後分割一次字符串,並在每個分割後添加"...":
<?php $str = "Hello world!" ; echo chunk_split ( $str , 6 , "..." ) ; ?>
親自試一試
chunk_split ( string , length , end )
參數 | 描述 |
---|---|
string | 必需。規定要分割的字符串。 |
length | 可選。數字值,定義字符串塊的長度。默認是76。 |
end | 可選。字符串值,定義在每個字符串塊末端放置的內容。默認是\r\n。 |