PHP chunk_split() Function

PHP addcslashes() Function
PHP convert_cyr_string() Function

In this article, you will learn how to split a string into small portions. The PHP chunk_split() function split a string into series of small chunks. This function does not change the original string. It returns the chunks from the given string according to the specified length and ending.

What is the syntax of the chunk_split() function in PHP?

chunk_split(string,length,end)
ParametersDetails
stringThe string to split in portions – Required
lengthThe length of the chunks of the string – Optional – Default: 76
endIf you want to place some character at the end of each chunk – Default: \r\n
PHP chunk_split() function

Examples of the chunk_split() function

Example 1. In this example, we simply split the string after one character and place comma after each one.

<?php
$str = "Hello world!";
echo chunk_split($str,1,",");
?>

Example 2. In this example, we split the string into chunks of 6 characters and place ! at the end of the each chunk.

<?php
$str = "Hello world!";
echo chunk_split($str,6,"!");
?>
PHP addcslashes() Function
PHP convert_cyr_string() Function
en English
X
Scroll to Top