From ddf5ccdce8d8be4e3033e6009ea8ac408f32aeb9 Mon Sep 17 00:00:00 2001 From: gnuboard Date: Wed, 17 Apr 2013 09:45:37 +0900 Subject: [PATCH] =?UTF-8?q?UTF8=20=EB=AC=B8=EC=9E=90=EC=97=B4=20=EC=A0=9C?= =?UTF-8?q?=EB=8C=80=EB=A1=9C=20=EC=9E=98=EB=9D=BC=EC=A3=BC=EB=8A=94=20utf?= =?UTF-8?q?8=5Fstrcut=20=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common.lib.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/common.lib.php b/lib/common.lib.php index 9665a7f76..6ec14dc20 100644 --- a/lib/common.lib.php +++ b/lib/common.lib.php @@ -1612,6 +1612,26 @@ function is_utf8($str) } +// UTF-8 문자열 자르기 +// 출처 : https://www.google.co.kr/search?q=utf8_strcut&aq=f&oq=utf8_strcut&aqs=chrome.0.57j0l3.826j0&sourceid=chrome&ie=UTF-8 +function utf8_strcut( $str, $size, $suffix='...' ) +{ + $substr = substr( $str, 0, $size * 2 ); + $multi_size = preg_match_all( '/[\x80-\xff]/', $substr, $multi_chars ); + + if ( $multi_size > 0 ) + $size = $size + intval( $multi_size / 3 ) - 1; + + if ( strlen( $str ) > $size ) { + $str = substr( $str, 0, $size ); + $str = preg_replace( '/(([\x80-\xff]{3})*?)([\x80-\xff]{0,2})$/', '$1', $str ); + $str .= $suffix; + } + + return $str; +} + + /* ----------------------------------------------------------- Charset 을 변환하는 함수