Sep 15

[代码]中文字符截取类 不指定

bkkkd , 00:18 , 开发应用 , 评论(0) , 引用(0) , 阅读(4880) , Via 本站原创 | |
class String



{



   /**



    * subStrWithSuffix



    * 中文字符截取 (Mon Aug 01 11:13:34 CST 2005)



    * @version        1.0.0



    * @author        



    * @deprecated    解决中文截取出现乱码



    * @return        string



    */



   function subStrWithChr ($string, $length, $start = 0)



   {



       if ($start < 0 || ($stringLength = strlen($string)) < $start) return $string;



       $length = (($length < 1 || $length > $stringLength)?$stringLength:$length);


for ($i = 1, $o = ($start % 2)?2:1; ($start > 0 && $i
< $o && ord(substr($string, $start , 1)) > 0xa0); $i ++)
$start --;


for ($i = 1, $o = ($length % 2)?2:1; ($stringLength > $length
&& $i < $o && ord(substr($string, $length - 1 ,
$length)) > 0xa0); $i ++) $length ++;



       $string = substr($string, $start, $length);



       return $string;



   }







   /**



    * wordWrapWithChr



    * 字符截行 (Mon Aug 01 14:15:37 CST 2005)



    * @version        1.0.0



    * @author        



    * @deprecated    解决中文截取出现乱码



    * @return        string



    */



   function wordWrapWithChr ($string, $width, $break = null)



   {



       /**



        * 中文标点符号怎么处理?暂时没有比较好的解决方案



        * ,。?:;’‘“”、()*……—…%¥€$£·!



        */


for ($break = $break?$break:"\n", $line = 0, $text = array(),
$handle = 0, $length = strlen($string); $handle < $length; $handle
+= strlen($text[$line ++]))



           $text[$line] = String::subStrWithChr($string, $width, $handle);



       return implode($break, $text);/*  */



   }



}



function startTimer()



{



   global $starttime;



   $mtime = microtime ();



   $mtime = explode (' ', $mtime);



   $mtime = $mtime[1] + $mtime[0];



   $starttime = $mtime;



}



function endTimer()



{



   global $starttime;



   $mtime = microtime ();



   $mtime = explode (' ', $mtime);



   $mtime = $mtime[1] + $mtime[0];



   $endtime = $mtime;



   $totaltime = round (($endtime - $starttime), 5);



   return $totaltime;



}



?>
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]