PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




chunk_split

Name

chunk_split — Breaks a string into a series of smaller chunks.

Synopsis

string chunk_split(string[, chunk_length][, chunk_ending]);
string string: String to split into chunks
int chunk_length (optional): Length of the chunks (default76)
string chunk_ending (optional): Character(s) to place at the end of each chunk (default\r\n)

Returns

String with chunk_ending placed every chunk_length

Description

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.

Note

This function should not be used for breaking long lines of text into shorter lines for display purposes - use wordwrap() instead.

Version

PHP 3.0.6+, PHP 4+

See also

To wrap text in a human-friendly fashion:

wordwrap()



Example

Example 1194. Make base64 encoded text 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.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.