From 7c6569294ef8986fb16f6be3208bf1c73892f9f7 Mon Sep 17 00:00:00 2001 From: zero Date: Thu, 18 Sep 2008 04:58:40 +0000 Subject: [PATCH] =?UTF-8?q?17288973=20=EB=AC=B8=EC=9E=90=EC=97=B4=20?= =?UTF-8?q?=EC=9E=90=EB=A5=B4=EB=8A=94=20=ED=95=A8=EC=88=98=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://xe-core.googlecode.com/svn/sandbox@4517 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- config/func.inc.php | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/config/func.inc.php b/config/func.inc.php index 82dc006c5..2c81afcd3 100644 --- a/config/func.inc.php +++ b/config/func.inc.php @@ -207,14 +207,34 @@ * @param cut_size 주어진 원 문자열을 자를 크기 * @param tail 잘라졌을 경우 문자열의 제일 뒤에 붙을 꼬리 * @return string - * - * 손쉽고 확실한 변환을 위해 2byte unicode로 변형한후 처리를 한다 **/ - function cut_str($string, $cut_size, $tail='...') { - if(!$string || !$cut_size) return $string; + function cut_str($string,$cut_size,$tail = '...') { + if(!$string) return $string; - $arr = array(); - return preg_match('/.{'.$cut_size.'}/su', $string, $arr) ? $arr[0].$tail : $string; + $char_width = Array(5,10,11,16,14,16,16,10,11,11,12,13,10,13,10,12,13,13,13,13,13,13,13,13,13,13,10,10,14,13,14,13,16,15,15,16,15,15,14,16,15,8,13,15,14,16,16,16,15,16,15,15,14,16,15,16,16,15,15,13,16,13,13,11,10,14,14,14,14,14,10,14,14,8,9,13,8,16,14,15,14,14,10,14,10,14,13,16,14,13,14,14,14,14,16); + $unicode_width = 21; + + $max_width = $cut_size*$unicode_width/2; + $char_width = 0; + + $string_length = strlen($string); + $char_count = 0; + + $idx = 0; + while($idx < $string_length && $char_count < $cut_size && $char_width < $max_width) { + $c = ord(substr($string, $idx,1)); + $char_count++; + if($c<128) { + $char_width += (int)$char_width[$c-32]; + $idx++; + } else { + $char_width += $unicode_width; + $idx += 3; + } + } + $output = substr($string,0,$idx); + if(strlen($output)<$string_length) $output .= $tail; + return $output; } function zgap() {