<p class="listintro"><span id="sp"></span>汉字</p> <p style="width:340px;height:285px;float:left;"> </p> <li class="content" id="pre_1152192617"> <?php <br/><br>/***************************************************************************<br>* cut_string.php<br>* ------------------------------<br>* Date : Jul 16, 2005<br>* Copyright : none<br>* Mail : <br>*<br>* 作用:截取中文字符.<br>*<br>*<br>***************************************************************************/<br><br>function cut_str($string, $sublen, $start = 0, $code = 'UTF-8')<br>{<br>if($code == 'UTF-8')<br>{<br>$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]/";<br>preg_match_all($pa, $string, $t_string);<br><br>if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen))."...";<br>return join('', array_slice($t_string[0], $start, $sublen));<br>}<br>else<br>{<br>$start = $start*2;<br>$sublen = $sublen*2;<br>$strlen = strlen($string);<br>$tmpstr = '';<br>for($i=0; $i{<br>if($i>=$start && $i{<br>if(ord(substr($string, $i, 1))>129) $tmpstr.= substr($string, $i, 2);<br>else $tmpstr.= substr($string, $i, 1);<br>} <br>if(ord(substr($string, $i, 1))>129) $i++;<br>}<br>if(strlen($tmpstr)return $tmpstr;<br>}<br>}<br><br>?><br><br><br>cut_str(字符串, 截取长度, 开始长度, 编码);<br>编码默认为 utf-8<br>开始长度默认为 0 </li> <p style="width:100%;text-align:center;margin:10px 0"> <br> <br> </p> <p style="width:100%;text-align:center;margin:10px 0"> </p> <p class="clear"></p>