chunk_split
-
Splitting a long string into smaller chunks can be done in Ruby using a sequence of:
String#scanthe string into the specified chunk sizeArray#jointhe string back together using the ending sequence as the glueString#+appends the final ending sequence to the result
PHP
$result = chunk_split("a really long string", 5, "\r\n"); var_export($result); // => "a rea\r\nlly l\r\nong s\r\ntring\r\n"
Ruby
p "a really long string".scan(/.{1,5}/).join("\r\n") + "\r\n" # => "a rea\r\nlly l\r\nong s\r\ntring\r\n"
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

