[수정전]
function cut_str($string, $cut_size, $tail='...') {
if(!$string || !$cut_size) return $string;
if(function_exists('iconv')) {
$unicode_str = iconv("UTF-8","UCS-2",$string);
if(strlen($unicode_str) < $cut_size*2) return $string;
$output_str = substr($unicode_str, 0, $cut_size*2);
return iconv("UCS-2","UTF-8",$output_str).$tail;
}
$arr = array();
return preg_match('/.{'.$cut_size.'}/su', $string, $arr) ? $arr[0].$tail : $string;
}
[수정후]
function cut_str($string, $cut_size, $tail) {
$width = Array(0, 12, 4, 4, 4, 6, 6, 10, 8, 4, 5, 5, 6, 6, 4, 6, 4, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 4, 8, 6, 8, 6, 12, 8, 8,
9, 8, 8, 7, 9, 8, 3, 6, 8, 7, 11, 9, 9, 8, 9, 8, 8, 8, 8,
8, 10, 8, 8, 8, 6, 11, 6, 6, 6, 4, 7, 7, 7, 7, 7, 3, 7,
7, 3, 3, 6, 3, 11, 7, 7, 7, 7, 4, 7, 3, 7, 6, 10, 7, 7,
7, 6, 6, 6, 9, 0);
$str_buffer = "";
$len_buffer = 0;
$count = 0;
$len = strlen($string);
$cut_size = $width[1] * $cut_size / 2;
while( $count < $len ) {
$asc = ord(substr($string, $count, 1));
if( $asc < 128 ) {
$len_buffer += $width[$asc-30];
if( $len_buffer > $cut_size ) {
$str_buffer .= "...";
break;
}
$str_buffer .= substr($string, $count, 1);
$count += 1;
} else {
$len_buffer += $width[1];
if( $len_buffer > $cut_size ) {
$str_buffer .= "...";
break;
}
$str_buffer .= substr($string, $count, 3);
$count += 3;
}
}
if ($tail) return "$str_buffer";
else return $str_buffer."";
}
/config/func.inc.php
201 라인부터 수정해 주시면 됩니다.
태터툴즈 블로그 사용할 때 쓰던건대...
이 팁을 적용하니 거의 같은 길이로 자르네요.
일일이 위젯과 게시판의 문자수를 바꾸어 주어야 하지만 좋은팁입니다.
[수정전] [수정후]