/**
* 处理csv导入的时间格式数据
* @param $strTime string 导入时间字符串
* @return $strtotimr int 转换后的时间戳
* @author lihu
*/
function disposeImportTimeData($strTime){
$strtoTime = strtotime($strTime);
//如果strtotime 转换成功,不执行以下代码
if ($strtoTime != false){
return $strtoTime;
}else{
$strTime = strtolower($strTime);
//导入时间格式参考值
$reference = [
"rrrr年r月rr日",
"rrrr年r月r日",
"rrrr年r月rr日",
"rrrr年r月rr日 r:rr",
"rrrr年r月rr日 rr:r",
"rrrr年r月rr日 rr:rr",
"rrrr年r月rr日 rr:rr:rr",
"rrrr年r月rr日 r:rr:r",
"rrrr年r月rr日 r:r:rr",
"rrrr年r月rr日 rr:r:r",
"rrrr年r月rr日 r:r:r",
"rrrr年rr月r日",
"rrrr年rr月r日 r:rr",
"rrrr年rr月r日 rr:r",
"rrrr年rr月r日 rr:rr",
"rrrr年rr月r日 rr:rr:rr",
"rrrr年rr月r日 r:rr:r",
"rrrr年rr月r日 r:r:rr",
"rrrr年rr月r日 rr:r:r",
"rrrr年rr月r日 r:r:r",
"rrrr年rr月rr日",
"rrrr年rr月rr日 r:rr",
"rrrr年rr月rr日 rr:r",
"rrrr年rr月rr日 rr:rr",
"rrrr年rr月rr日 rr:rr:rr",
"rrrr年rr月rr日 r:rr:r",
"rrrr年rr月rr日 r:r:rr",
"rrrr年rr月rr日 rr:r:r",
"rrrr年rr月rr日 r:r:r",
"rrrr/r/r rr:rr am",
"rrrr/r/r r:rr am",
"rrrr/r/r rr:r am",
"rrrr/r/r rr:rr pm",
"rrrr/r/r r:rr pm",
"rrrr/r/r rr:r pm",
"rrrr/rr/rr rr:rr am",
"rrrr/rr/rr rr:r am",
"rrrr/rr/rr r:rr am",
"rrrr/rr/rr rr:rr pm",
"rrrr/rr/rr r:rr pm",
"rrrr/rr/rr rr:r pm",
"rrrr-r-r rr:rr am",
"rrrr-r-r r:rr am",
"rrrr-r-r rr:r am",
"rrrr-r-r rr:rr pm",
"rrrr-r-r r:rr pm",
"rrrr-r-r rr:r pm",
"rrrr-rr-rr rr:rr am",
"rrrr-rr-rr rr:r am",
"rrrr-rr-rr r:rr am",
"rrrr-rr-rr rr:rr pm",
"rrrr-rr-rr r:rr pm",
"rrrr-rr-rr rr:r pm",
];
$replaceValue = str_replace([
'0','1','2','3','4','5','6','7','8','9',
"零","一","二","三","四","五","六","七","八","九"
],"r", $strTime);
if(in_array($replaceValue,$reference)){
//是否存在中文
if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $strTime)){
//中文"年","月","日"转"-",汉字数字转数字
$strTime = str_replace(['年','月','日'],"-", $strTime);
$strTime = str_replace(['时','分','秒'],":", $strTime);
//转换中文数字
$arrTime = switchChnNumber($strTime);
if(empty($arrTime)){
return false;
}
//去除多余 “-” 或 “:”
$strTime = trimTimeArr($arrTime);
return strtotime($strTime);
}else{
return strtotime($strTime);
}
}else{
return false;
}
}
}
/**
* 处理 字符串替换后的多余值
* @param $arrTime
* @return array|string
* @author lihu
*/
function trimTimeArr($arrTime){
$arrTime = $arrTime." ";
$arrTime = explode(" ", $arrTime);
$arrTime[0] = rtrim($arrTime[0], "-");
$arrTime[1] = rtrim($arrTime[1], ":");
$arrTime = implode(" ", $arrTime);
$arrTime = rtrim($arrTime, " ");
return $arrTime;
}
/**
* 中文 一、二... 转阿拉伯数字
* @param $time
* @return string
* @author lihu
*/
function switchChnNumber($time){
if(!empty($time)){
$replaceValueC = [
"零"=>0,"一"=>1,"二"=>2,"三"=>3,"四"=>4,"五"=>5,"六"=>6,"七"=>7,"八"=>8,"九"=>9
];
//拆分含有中文的字符串
$arrTime = preg_split('/(? $value){
if($replaceValueC[$value] != ''){
$arrTime[$key] = $replaceValueC[$value];
}else{
$arrTime[$key] = $value;
}
}
return implode("", $arrTime);
}else{
return $time;
}
}