PHP chunk_split() Function

PHP chunk_split() Function

The chunk_split() function in PHP splits a string into a series of smaller parts.

Syntax

chunk_split(string,length,end)

Parameter

string(required)- It specifies the string to split.

length(optional)- This parameter represents a number that defines the length of the chunks. Its default value is 76.

end(optional)- This parameter signifies a string that defines what to place at the end of each chunk and its default value is \r\n.

Return

This function returns the chunked string.

Example 1

    

Output

 Original string: Hello World
 After 'chunk_split()' function
 New string: Hello ...World...   

Example 2

    

Output

 Original string: HelloWorld
 After 'chunk_split()' function
 New string: H...e...l...l...o...W...o...r...l...d...   

Example 3

    

Output

PHP Warning: chunk_split(): Chunk length should be greater than zero in /workspace/Main.php on line 7