As an alternative for qeremy [atta] gmail [dotta] com
There is much shorter way for binarysafe chunking of multibyte string:
<?php
function word_chunk($str, $len = 76, $end = "\n") {
$pattern = '~.{1,' . $len . '}~u'; // like "~.{1,76}~u"
$str = preg_replace($pattern, '$0' . $end, $str);
return rtrim($str, $end);
}
$str = 'русский';
echo chunk_split($str, 3) ."\n";
echo word_chunk($str, 3) . "\n";
?>
р�
�с
с�
�и
й
рус
ски
й