function msubstr($str, $start, $len) { $tmpstr = ""; $strlen = $start + $len; for($i = 0; $i < $strlen; $i++) { if(ord(substr($str, $i, 1)) > 0xa0) { $tmpstr .= substr($str, $i, 2); $i++; } else $tmpstr .= substr($str, $i, 1); } ///我写的 if (strlen($lline[$maxname])>40) { $temp = '' ;//initialize for ($i=0;$i<40;){ if (ord(substr($lline[$maxname],$i,1))>0x7F) {//the higher part>0x7F, this may be a Chinese Word $temp .= substr($lline[$maxname],$i,2) ; $i = $i + 2; } else {//an English Word maybe $temp .= substr($lline[$maxname],$i,1) ; $i++ ; } } $lline[$maxname] = $temp."..." ; //now, it's ok to process Chinese } return $tmpstr; }
截取汉字的函数
最新推荐文章于 2005-06-13 21:19:00 发布