From 5a197395aee5407f86c22649fb0191fb2bc370e0 Mon Sep 17 00:00:00 2001 From: ejikharev Date: Mon, 2 Feb 2009 11:13:25 +0000 Subject: [PATCH] add wordwrap function for utf text git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@55 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- classes/Sublimer.class.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/classes/Sublimer.class.php b/classes/Sublimer.class.php index 13284d0..7d5aba6 100644 --- a/classes/Sublimer.class.php +++ b/classes/Sublimer.class.php @@ -107,6 +107,29 @@ final class Sublimer 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); + } + + } ?> \ No newline at end of file