use mbstring to split chinese characters
This commit is contained in:
parent
3d83f3278c
commit
d4623f453d
|
|
@ -66,4 +66,34 @@ class Utils
|
|||
return $fname;
|
||||
}
|
||||
|
||||
public static function getStringOmitted($str, $length, $append = true)
|
||||
{
|
||||
$str = trim($str);
|
||||
$strlength = strlen($str);
|
||||
|
||||
if ($length == 0 || $length >= $strlength) {
|
||||
return $str;
|
||||
} elseif ($length < 0) {
|
||||
$length = $strlength + $length;
|
||||
|
||||
if ($length < 0) {
|
||||
$length = $strlength;
|
||||
}
|
||||
}
|
||||
|
||||
if (function_exists('mb_substr')) {
|
||||
$newstr = mb_substr($str, 0, $length, 'utf-8');
|
||||
} elseif (function_exists('iconv_substr')) {
|
||||
$newstr = iconv_substr($str, 0, $length, 'utf-8');
|
||||
} else {
|
||||
$newstr = substr($str, 0, $length);
|
||||
}
|
||||
|
||||
if ($append && $str != $newstr) {
|
||||
$newstr .= '...';
|
||||
}
|
||||
|
||||
return $newstr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
<img src="./preview/{{ $texture['tid'] }}.png">
|
||||
</div>
|
||||
<div class="item-footer">
|
||||
<span title="{{ $texture['name'] }}">{{ strlen($texture['name']) > 12 ? substr($texture['name'], 0, 12).'...' : $texture['name']}} <small>({{ $texture['type'] }})</small></span>
|
||||
<span title="{{ $texture['name'] }}">{{ Utils::getStringOmitted($texture['name'], 12) }} <small>({{ $texture['type'] }})</small></span>
|
||||
@if (isset($_SESSION['email']))
|
||||
|
||||
@if ($user->closet->has($texture['tid']))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user