/**
* 字符串截取函數(shù) 自動清除網(wǎng)頁標簽
**/
Function str_cut($string, $length = 80, $etc = '...', $code = 'UTF-8')
{
$string = strip_tags(preg_replace('!\s+!', $string, ' '));
if ($length == 0)
return '';
if ($code == 'UTF-8') {
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
}
else {
$pa = "/[\x01-\x7f]|[\xa1-\xff][\xa1-\xff]/";
}
preg_match_all($pa, $string, $t_string);
if (count($t_string[0]) > $length)
return join('', array_slice($t_string[0], 0, $length)) . $etc;
return join('', array_slice($t_string[0], 0, $length));
}
中山php|最優(yōu)網(wǎng)絡 :中山做網(wǎng)站 中山php建站
最優(yōu)良人
2012/06/07 at 17:40
php字符串截取函數(shù),自動清除網(wǎng)頁標簽
in: 后端程序