Sep
15
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;
}
?>
{
/**
* 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;
}
?>