php对中文的支持不怎么好哦,特别在我一个字符串中有中文与英语时截取就是个问题了,处理不好就会出现乱码了,下面我们这截取中文字符串函数就很好的处理了这件事情。
C编写,实现字符串摘要、文件摘要两个功能。里面主要包含3个文件: Md5.cpp、Md5.h、Main.cpp。其中Md5.cpp是算法的代码,里的代码大多是从 rfc-1321 里copy过来的;Main.cpp是主程序。
0
function MooCutstr($string, $length, $dot = ' ...') {
global $charset;
if(strlen($string)
return $string;
}
$string = str_replace(array('&', '"', '<', '>'), array('&', '"', ''), $string);
$strcut = '';
if(strtolower($charset) == 'utf-8') {
$n = $tn = $noc = 0;
while($n
$t = ord($string[$n]);
if($t == 9 || $t == 10 || (32
$tn = 1; $n++; $noc++;
} elseif (194
$tn = 2; $n += 2; $noc += 2;
} elseif (224
$tn = 3; $n += 3; $noc += 2;
} elseif (240
$tn = 4; $n += 4; $noc += 2;
} elseif (248
$tn = 5; $n += 5; $noc += 2;
} elseif ($t == 252 || $t == 253) {
$tn = 6; $n += 6; $noc += 2;
} else {
$n++;
}
if($noc >= $length) {
break;
}
}
if($noc > $length) {
$n -= $tn;
}
$strcut = substr($string, 0, $n);
} else {
for($i = 0; $i
$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
}
}
$strcut = str_replace(array('&', '"', ''), array('&', '"', '<', '>'), $strcut);
return $strcut.$dot;
}
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号