PHP chunk_split() Function
In this chapter you will learn:
- Definition for PHP chunk_split() Function
- Syntax for PHP chunk_split() Function
- Parameter for PHP chunk_split() Function
- Return for PHP chunk_split() Function
- Note for PHP chunk_split() Function
- Example - Split the string after each character and add a "." after each split
- Example - Split the string after each sixth character and add a "..." after each split
Definition
The chunk_split() function splits a string into a series of smaller parts.
Syntax
PHP chunk_split() function has the following syntax.
chunk_split(string,length,end)
Parameter
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 |
Return
PHP chunk_split() Function returns the split string.
Note
This function does not alter the original string.
Example 1
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.
Example 2
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.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP convert_cyr_string() Function
- Syntax for PHP convert_cyr_string() Function
- Parameter for PHP convert_cyr_string() Function
- Supported Cyrillic character-sets
- Return for PHP convert_cyr_string() Function
- Example - Convert a string from one character-set to another
Home » PHP Tutorial » PHP String Functions