The `chunk_split()` string function in PHP 8.4 is used to split a string into smaller chunks, inserting a specified separator between each chunk. This is particularly useful when formatting strings such as base64 encoded data to match specific standards like RFC 2045.
Example : Splitting a String into 10-Character Chunks
<?php $text = "The quick brown fox jumps over the lazy dog."; $chunkedText = chunk_split($text, 10, "\n"); echo $chunkedText; ?>
Output:
The quick brown fox jumps over the lazy dog.
In this example, the string is divided into chunks of 10 characters each, with a newline character (`”\n”`) inserted after every chunk.