/**
* utf-8中文截取,单字节截取模式
*
* @access public
* @param string $str 需要截取的字符串
* @param int $slen 截取的长度
* @param int $startdd 开始标记处
* @return string
*/
function cn_substr_utf8($str, $length, $start=0)
{
if(strlen($str) < $start+1)
{
return '';
}
preg_match_all("/./su", $str, $ar);
$str = '';
$tstr = '';
//为了兼容mysql4.1以下版本,与数据库varchar一致,这里使用按字节截取
for($i=0; isset($ar[0][$i]); $i++)
{
if(strlen($tstr) < $start)
{
$tstr .= $ar[0][$i];
}
else
{
if(strlen($str) < $length + strlen($ar[0][$i]) )
{
$str .= $ar[0][$i];
}
else
{
break;
}
}
}
return $str;
}
/**
*获取昨天、上周、上月、等时间戳
* @param $time int -1:昨天 -7:上周 7:本周 -30:上个月 30:这个月 0:全部
* return array();
*/
function gettime($time){
switch($time){
case -1;
$time_s = mktime(0,0,0,date("m", strtotime("-1 day")), date("d",strtotime("-1 day")), date("Y",strtotime("-1 day")));
$time_e = mktime(23,59,59,date("m", strtotime("-1 day")), date("d",strtotime("-1 day")), date("Y",strtotime("-1 day")));
break;
case -7;
$time_s = mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"));
$time_e = mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"));
break;
case -30;
$time_s = mktime(0, 0, 0, date('m')-1, 1, date('y'));
$time_e = mktime(23, 59, 59, date('m'), 0, date('y'));
break;
case -360;
$time_s = mktime(0, 0 , 0,1,1,date("Y")-1);
$time_e = mktime(23,59,59,12,31,date("Y")-1);
break;
case 7;
$time_s = mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"));
$time_e = mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"));
break;
case 30;
$time_s = mktime(0, 0 , 0,date("m"),1,date("Y"));
$time_e = mktime(23,59,59,date("m"),date("t"),date("Y"));
break;
case 360;
$time_s = mktime(0, 0 , 0,1,1,date("Y"));
$time_e = mktime(23,59,59,12,31,date("Y"));
break;
default;
return 0;
}
return array($time_s,$time_e);
}