The chunk_split() function splits a string into a series of smaller parts.
PHP chunk_split() function has the following syntax.
chunk_split(string,length,end)
Parameter | Is Required | Description |
---|---|---|
string | Required. | 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 chunk_split() Function returns the split string.
This function does not alter the original string.
Split the string after each character and add a "." after each split:
<?php
$str = "Hello world from java2s.com!";
echo chunk_split($str,1,".");
?>
The code above generates the following result.
Split the string after each sixth character and add a "..." after each split:
<?php
$str = "Hello world from java2s.com!";
echo chunk_split($str,6,"...");
?>
The code above generates the following result.