add wordwrap function for utf text
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@55 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
@ -107,6 +107,29 @@ final class Sublimer
|
|||||||
return mb_substr($text, 0, $count).$postfix;
|
return mb_substr($text, 0, $count).$postfix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Выполняет разрыв строки на данное количество символов с использованием символа разрыва (wordwrap для utf)
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param int $width
|
||||||
|
* @param string $break
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function wrapString($text, $width = 15, $break = " ")
|
||||||
|
{
|
||||||
|
$words = explode(' ', $text);
|
||||||
|
for ($i = 0; $i < count($words); $i++) {
|
||||||
|
if (mb_strlen($words[$i]) > $width) {
|
||||||
|
for ($j = $width; $j < mb_strlen($words[$i]); $j += $width + (mb_strlen($break))) {
|
||||||
|
$words[$i] = mb_substr($words[$i], 0, $j) . $break . mb_substr($words[$i], $j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return implode(' ', $words);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Reference in New Issue
Block a user