作为 qeremy [atta] gmail [dotta] com 的替代方案
对于多字节字符串的二进制安全分块,有一个更短的方法
<?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";
?>
р�
�с
с�
�и
й
рус
ски
й