php字串截取函數,支援中英文混體,以前我們截取字串都會用php自帶的函數,今天我來看一下一款字串截取函數,支援中英文混體的php程式碼實例吧.
php字串截取函數程式碼如下:
function cutstr($string, $sublen=10, $start = 0, $code = 'utf-8')
{ $code = 'utf-8')
{ $code = 'utf-8') 8')
{
$pa = "/[x01-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf][x80-xdf][x80-xbf]|xe0[xa0-xbf][x80-xf]|[xe1-xef]| xbf][x80-xbf]|xf0[x90-xbf][x80-xbf][x80-xbf]|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf]/";
preg_match_all($pa, $string, $t_string);
//if(count($t_string[0]) - $start > $sublen) return join('', - $start > $sublen) return join(』 $sublen))."...";
return join('', array_slice($t_string[0], $start, $sublen));
h🜠));
start*2; $sublen = $sublen*2; $strlen = strlen($string); $tmpstr. ) { if($i>=$start && $i { if(ord(substrstring,$)$ .= substr($string, $i, 2); else $tmpstr.= substr($string, $i, 1); )>129) $i++;
}//開源軟體:phpfensi.com
//if(strlen($tmpstr) }
}