<?php
function toFixLen($str,$len){ //固定長度字符串的截取
if($len>=strlen($str)||!$len) return $str;
$len-=3;
$tempstr1 = substr($str,0,$len); //截取字符串
$tempstr2 = preg_replace('/([/x81-/xff]+)$/ms','',$tempstr1,1); //去掉結尾的連續漢字字符
if(!is_int((strlen($tempstr1)-strlen($tempstr2))/2)){ //去掉的字符爲奇數?
$tempstr1 = substr($str,0,$len-1);
}
return $tempstr1."…";
}
?>
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/renren000/archive/2009/02/02/3858694.aspx