PHP chunk_split() Function Example Tutorial
PHP chunk_split() Function Example Tutorial is today’s topic. The chunk_split() function splits the string into a series of smaller parts. It does not return the original string. So, it is not a pure function. The chunk_split() function is the built-in function in PHP. The function is used to split the string into smaller chunks of the specific length.
PHP chunk_split() Function
PHP chunk_split() function is used to split or divide the string into chunks or small parts. It returns the split string.
The syntax of the function is following.
string chunk_split($string, $length, $end)
- The $string parameter specifies a string which is needed to be chunked.
- The $length parameter specifies an integer which defines the chunk length. That is the length of the chunked parts.
- The $end parameter specifies the line ending sequence.
See the code example.
<?php $str = "BobbyBrown"; echo chunk_split($str, 5, "...");
See the output.
➜ pro php app.php Bobby...Brown... ➜ pro
See another example of Friends.
<?php $centralperk = "FRIENDS"; echo chunk_split($centralperk, 1, ".");
See the output.
➜ pro php app.php F.R.I.E.N.D.S. ➜ pro
Remember, The chunk_split() function doesn’t return an array, but rather a string.
If you want to use it, you would have to convert the string returned by the chunk_split() function into an array.
The result of chunk_split() in PHP 5.0.4 does not match the result in other versions of PHP.
Finally, PHP chunk_split() Function Example Tutorial is over.