Using PHP chunk_split() to Split Strings into Fixed‑Size Chunks
This article explains PHP's chunk_split() function, detailing its purpose of dividing a string into fixed-size pieces, describing its parameters (body, chunklen, end), return value, and providing a practical example that formats base64‑encoded data according to RFC 2045.
Daily PHP knowledge sharing introduces the chunk_split() function, which splits a string into smaller chunks.
The function is useful for formatting the output of base64_encode() to comply with RFC 2045, inserting a specified end string after every $chunklen characters.
Parameters
body : the string to be split.
chunklen : the size of each chunk (default 76).
end : the line‑ending sequence to append after each chunk (default "\r\n").
Return value
The function returns the split string.
Example
<?php
// Format $data using RFC 2045 semantics
$new_string = chunk_split(base64_encode($data));
?>Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
