本文共 1508 字,大约阅读时间需要 5 分钟。
define(CHARSET, 'UTF-8'); // 系统默认编码 function cutstr( $string, $length, $dot = '...' ) { if ( strlen( $string ) <= $length ) { $string = str_replace( array( '&', '"', '<', '>' ), array( $pre . '&' . $end, $pre . '"' . $end, $pre . '<' . $end, $pre . '>' . $end ), $string ); if ( strtolower( CHARSET ) == 'utf-8' ) { while ( $n < strlen( $string ) ) { if ( $t == 9 $t == 10 (32 <= $t && $t <= 126) ) { } elseif ( 194 <= $t && $t <= 223 ) { } elseif ( 224 <= $t && $t <= 239 ) { } elseif ( 240 <= $t && $t <= 247 ) { } elseif ( 248 <= $t && $t <= 251 ) { } elseif ( $t == 252 $t == 253 ) { $strcut = substr( $string, 0, $n ); for ( $i = 0; $i < $length; $i++ ) { $strcut .= ord( $string[$i] ) > 127 ? $string[$i] . $string[++$i] : $string[$i]; $strcut = str_replace( array( $pre . '&' . $end, $pre . '"' . $end, $pre . '<' . $end, $pre . '>' . $end ), array( '&', '"', '<', '>' ), $strcut ); $pos = strrpos( $strcut, chr( 1 ) ); $strcut = substr( $strcut, 0, $pos ); 转载地址:http://shqgi.baihongyu.com/