This function is somewhat similar to wordwrap() in that some characters are inserted into a string at an interval. With chunk_split(), though, there is no thought about words and white space.

The default values are 76 (length of each chunk) and “\r\n” (the string to insert) which allows us to deduce that its use was meant for something specific (base64) and not so much for everyday display text. But, of course, it can be used for anything you like.

If the chunk length is less than one, false is returned and a warning is given. It always puts the insert string at the end, even if it didn’t reach the number of characters indicated by the length given.

$str = "Choking on the ashes of her enemy";
 
$new = chunk_split($str, 17, 'Q');  // 'Choking on the asQhes of her enemyQ'
$new = chunk_split($str, 200, 'Q'); // 'Choking on the ashes of her enemyQ'
$new = chunk_split($str);           // "Choking on the ashes of her enemy\r\n"
$new = chunk_split($str, 0, 'Q');   // false