function cutstr($string, $length, $etc = '') {
if (empty($string)) {
return '';
}
$result = '';
$total = strlen($string);
$i = 0;
while ($length > 0 && $i < $total) {
$var = str_pad(decbin(ord($string[$i])), 8, '0', STR_PAD_LEFT);
if ($skip = strpos($var, '0')) {
$length -= 2;
} else {
$skip = 1;
$j = $i + 2;
$length--;
}
$result .= substr($string, $i, $skip);
$i += $skip;
}
return $result.($i < $total ? $etc : '');
}
PHP-UTF8中英文截取字符串实例
最新推荐文章于 2021-03-13 06:27:45 发布