From 8585d7a90ea70eb9539c5e6827efd16c52cb517d Mon Sep 17 00:00:00 2001 From: chicpro Date: Fri, 18 Jan 2013 14:31:57 +0900 Subject: [PATCH] =?UTF-8?q?cut=5Fstr=20=ED=95=A8=EC=88=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common.lib.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/common.lib.php b/lib/common.lib.php index 625813969..f41fdcd00 100644 --- a/lib/common.lib.php +++ b/lib/common.lib.php @@ -1071,6 +1071,7 @@ function cut_str($str, $len, $suffix="…") global $g4; if (strtoupper($g4['charset']) == 'UTF-8') { + /* if (strlen($str) >= $len) { //echo $str,', ',strlen($str),', ',$len; $c = substr(str_pad(decbin(ord($str[$len-1])),8,'0',STR_PAD_LEFT),0,2); @@ -1080,6 +1081,17 @@ function cut_str($str, $len, $suffix="…") } else { return $str; } + */ + if (strlen($str) >= $len) { + $length = floor($len / 3); + + $arr_str = array_slice(preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY), 0, $length); + $string = join("", $arr_str); + + return $string . (strlen($str)-strlen($suffix) >= $len ? $suffix : ''); + } else { + return $str; + } } else { $s = substr($str, 0, $len); $cnt = 0; @@ -1671,7 +1683,7 @@ function skin_path() } -function is_mobile() +function is_mobile() { return preg_match('/'.G4_MOBILE_AGENT.'/i', $_SERVER['HTTP_USER_AGENT']); }