chunk_split() adds the character(s) specified in chunk_ending every chunk_length characters. This function is useful for breaking certain types of data into separate lines of a specified length. It's often used to make base64 encoded data conform to RFC 2045.
<?php $soliloquy = <<<RICHARDIII Now is the winter of our discontent Made glorious summer by this sun of York; And all the clouds that lour'd upon our house In the deep bosom of the ocean buried.\n\n RICHARDIII; echo "Original Text:\n", $soliloquy; echo "RFC2045 Compliant Text:\n", chunk_split(base64_encode($soliloquy)); ?> Output: Original Text: Now is the winter of our discontent Made glorious summer by this sun of York; And all the clouds that lour'd upon our house In the deep bosom of the ocean buried. RFC2045 Compliant Text: ICAgIE5vdyBpcyB0aGUgd2ludGVyIG9mIG91ciBkaXNjb250ZW50CiAgICBNYWRlIGdsb3Jpb3Vz IHN1bW1lciBieSB0aGlzIHN1biBvZiBZb3JrOwogICAgQW5kIGFsbCB0aGUgY2xvdWRzIHRoYXQg bG91cidkIHVwb24gb3VyIGhvdXNlCiAgICBJbiB0aGUgZGVlcCBib3NvbSBvZiB0aGUgb2NlYW4g YnVyaWVkLgoK
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.