PHPのchunk_split()関数
例
各文字の後に文字列を分割し、「。」を追加します。各分割後:
<?php
$str = "Hello world!";
echo chunk_split($str,1,".");
?>
定義と使用法
1つのchunk_split()関数は、文字列を一連の小さな部分に分割します。
注:この関数は元の文字列を変更しません。
構文
chunk_split(string,length,end)
パラメータ値
Parameter | Description |
---|---|
string | Required. Specifies the string to split |
length | Optional. A number that defines the length of the chunks. Default is 76 |
end | Optional. A string that defines what to place at the end of each chunk. Default is \r\n |
技術的な詳細
戻り値: | 分割された文字列を返します |
---|---|
PHPバージョン: | 4歳以上 |
その他の例
例
6文字ごとに文字列を分割し、分割するたびに「...」を追加します。
<?php
$str = "Hello world!";
echo chunk_split($str,6,"...");
?>
❮PHP文字列リファレンス