вероятно все дело в том что русские символы занимают по 2 байта в то время как английские по 1 байту в кодировке utf-8
--
немного погуглив вот что нашел
function utf8_wordwrap($str, $width, $break, $cut = false) {
if (!$cut) {
$regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.',}\b#U';
} else {
$regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.'}#';
}
if (function_exists('mb_strlen')) {
$str_len = mb_strlen($str,'UTF-8');
} else {
$str_len = preg_match_all('/[\x00-\x7F\xC0-\xFD]/', $str, $var_empty);
}
$while_what = ceil($str_len / $width);
$i = 1;
$return = '';
while ($i < $while_what) {
preg_match($regexp, $str,$matches);
$string = $matches[0];
$return .= $string.$break;
$str = substr($str, strlen($string));
$i++;
}
return $return.$str;
}
function utf8_wordwrap($string, $width=75, $break="\n", $cut=false)
{
if($cut) {
// Match anything 1 to $width chars long followed by whitespace or EOS,
// otherwise match anything $width chars long
$search = '/(.{1,'.$width.'})(?:\s|$)|(.{'.$width.'})/uS';
$replace = '$1$2'.$break;
} else {
// Anchor the beginning of the pattern with a lookahead
// to avoid crazy backtracking when words are longer than $width
$pattern = '/(?=\s)(.{1,'.$width.'})(?:\s|$)/uS';
$replace = '$1'.$break;
}
return preg_replace($search, $replace, $string);
}
/**
* Word wrap
*
* @param string $string
* @param integer $width
* @param string $break
* @param boolean $cut
* @param string $charset
* @return string
*/
function iconv_wordwrap($string, $width = 75, $break = "\n", $cut = false, $charset = 'utf-8')
{
$stringWidth = iconv_strlen($string, $charset);
$breakWidth = iconv_strlen($break, $charset);
if (strlen($string) === 0) {
return '';
} elseif ($breakWidth === null) {
throw new Zend_Text_Exception('Break string cannot be empty');
} elseif ($width === 0 && $cut) {
throw new Zend_Text_Exception('Can\'t force cut when width is zero');
}
$result = '';
$lastStart = $lastSpace = 0;
for ($current = 0; $current < $stringWidth; $current++) {
$char = iconv_substr($string, $current, 1, $charset);
if ($breakWidth === 1) {
$possibleBreak = $char;
} else {
$possibleBreak = iconv_substr($string, $current, $breakWidth, $charset);
}
if ($possibleBreak === $break) {
$result .= iconv_substr($string, $lastStart, $current - $lastStart + $breakWidth, $charset);
$current += $breakWidth - 1;
$lastStart = $lastSpace = $current + 1;
} elseif ($char === ' ') {
if ($current - $lastStart >= $width) {
$result .= iconv_substr($string, $lastStart, $current - $lastStart, $charset) . $break;
$lastStart = $current + 1;
}
$lastSpace = $current;
} elseif ($current - $lastStart >= $width && $cut && $lastStart >= $lastSpace) {
$result .= iconv_substr($string, $lastStart, $current - $lastStart, $charset) . $break;
$lastStart = $lastSpace = $current;
} elseif ($current - $lastStart >= $width && $lastStart < $lastSpace) {
$result .= iconv_substr($string, $lastStart, $lastSpace - $lastStart, $charset) . $break;
$lastStart = $lastSpace = $lastSpace + 1;
}
}
if ($lastStart !== $current) {
$result .= iconv_substr($string, $lastStart, $current - $lastStart, $charset);
}
return $result;
}