Table of Contents

Syntax

string chunk_split(string $str [, int $length [, string $end]])

(PHP 4, PHP 5)

$str The string value to be split into chunks
$length The maximum length of each piece of string split apart from $str. The default value is 76 characters.
$end The character sequence that denotes the end of each piece (and is appeneded after each chunk). The default sequence is ā€œ\r\nā€ (carriage return followed by a newline).
RETURNS Returns the modified string with line breaks between each piece

What it Does

Unlike the explode function which breaks apart a string into an array, the chunk_split function will reformat the string, inserting a character sequence (ā€œ\r\nā€ by default) after each chunk. Also, chunks are delimitted by string length and not individual characters.

Example

echo '<h4>chunk_split<h4>';
echo chunk_split($longtext);