PHP chunk_split()Functions
Examples
Split the string after each character and add "." after each split:
<?php
$str = "Hello world!";
echo chunk_split($str,1,".");
?>
$str = "Hello world!";
echo chunk_split($str,1,".");
?>
Run example »
Definition and Usage
The chunk_split() function splits a string into a series of smaller parts.
Note:This function does not change the original string.
Syntax
chunk_split(string,length,end)
| Parameters | Description |
|---|---|
| string | Required. Specifies the string to be split. |
| length | Optional. A number that defines the length of the string chunks. Default is 76. |
| end | Optional. A string that defines what to place after each string chunk. Default is \r\n. |
Technical Details
| Return value: | Returns the split string. |
|---|---|
| PHP Version: | 4+ |
More Examples
Example 1
Split the string after every six characters and add "..." after each split:
<?php
$str = "Hello world!";
echo chunk_split($str,6,"...");
?>
$str = "Hello world!";
echo chunk_split($str,6,"...");
?>
Run example »
PHP String Reference Manual Other Extensions