cut_str 함수 수정

This commit is contained in:
chicpro
2013-01-18 14:31:57 +09:00
parent b079d4358a
commit 8585d7a90e

View File

@ -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']);
}